How to serve static files in Nodejs from proxy on OPDK from a file system directory?

I am trying to server static files from Nodejs proxy. Since Nodejs support of "fs" module is limited to current working directory only I am not able to serve files from directories outside working directory.

One option could be to create a link of external directory say "/home/public-www/files" in current working directory. But the problem is every time we deploy proxy a new revision will be created and path to current working directory will change.

Is there a way to serve static files in apigee nodejs proxy?

Thanks!

Solved Solved
1 4 955
1 ACCEPTED SOLUTION

Hi @Diego Zuluaga,

Got this working using Java Callout on OPDK.

There is a way you can allow some Jar files access to higher directories.

Dino has answered similar question How API Proxy Can access File System.

Hope this will help others too.

Thanks..

View solution in original post

4 REPLIES 4

Not applicable

I think there are multiple answers to your questions.

var express = require('express'),
	app = express();
	path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
app.listen(9000);

However, your question seems to imply that you want to leverage a common folder outside across multiple API proxies. Is that right? Or better yet, could you provide a use case for this requirement? I got some ideas but just wanna make sure this is what you're looking for.

@Diego Zuluaga,

Thanks for the answer. I am having a SAN storage mounted in a folder and I want to serve that directory through edge proxy. I thought of creating a link to mounted SAN directory in current working directory but that will be a problem as I will have to do it manually each time, this will increase with the number of message processors and number of revisions. As with each revision path to Node app will change.

What I want to know is if there is way to enable file i/o in java or nodejs OPDK like a flag or property to be set.

Got it. Have you tried pushing symlinks during deployment time via apigeetool? Instead of creating the link after. I haven't tried it. But, you might get lucky. I wonder if plugins such as https://github.com/gruntjs/grunt-contrib-symlink might help.

Also, how many files are you planning to mount on the SAN? You could bundle up all dependencies with NPM on build time. If it's an API, I'd try to avoid as much as possible of external dependencies.

Hi @Diego Zuluaga,

Got this working using Java Callout on OPDK.

There is a way you can allow some Jar files access to higher directories.

Dino has answered similar question How API Proxy Can access File System.

Hope this will help others too.

Thanks..