Hi,
This API documentation explains how to install npm package for a particular proxy. Is it possible to install an npm package in such a was that it's available to all proxies?
Specifically, we would like to use AWS SDK for JS to simplify integration with AWS services. Since this SDK would be utilized by a number of proxies, it'd be preferable to maintain it "globally" rather than at an individual proxy level.
We're using Apigee On-Prem.
Thanks a lot in advance!
Maybe? I don't know, I have never tried it with a node_module. But Apigee Edge has the concept of a "resource". When you upload a nodejs script, you upload it as a proxy-specific resource. Along with the .ZIP files for modules that you depend on, and maybe other stuff.
There are other types of resources: jsc files, Java files, XSL files, and I think XSD and WSDL too.
All of these can be part of the API Proxy, as you know.
But, there is also the possibility to attach resources to the environment, and to the organization. You cannot (today) manage these through the Admin UI for Apigee Edge, but you can do it through the administrative API. The relevant doc that discusses these is here.
What I would try if I were you, is to zip up the node_module in question, or maybe start with a smaller one, and then manually upload it as a resourcefile to the org or environment (as appropriate). Use the Admin API for this.
Then see if you can require() that module from within multiple distinct proxies with nodejs targets.
Yes, it works. For me, it worked for a small module.
Here's how I tested it.
zipped the apigee-sample-module, along with its dependencies: actually just one: sprintf-js. The zip looked like this:
$ zip apigee-sample-module.zip -r node_modules/sprintf-js node_modules/apigee-sample-module adding: node_modules/sprintf-js/ (stored 0%) adding: node_modules/sprintf-js/dist/ (stored 0%) .... adding: node_modules/apigee-sample-module/ (stored 0%) adding: node_modules/apigee-sample-module/index.js (deflated 40%) adding: node_modules/apigee-sample-module/LICENSE (deflated 65%) adding: node_modules/apigee-sample-module/package.json (deflated 75%) adding: node_modules/apigee-sample-module/README.md (deflated 23%)
uploaded that zip as a resourcefile, like this:
curl -i -n -X POST $mgmtserver/v1/o/$orgname/resourcefiles\?type=node\&name=apigee-sample-module.zip \ --header "Content-Type:application/octet-stream" \ --data-binary @apigee-sample-module.zip
@Andrei Filippov -- I've also never tried this. But I did find that the doc states that Node resources can only be scoped to the proxy: http://docs.apigee.com/api-services/content/resource-files#node.
However, this restriction seems to apply only to Node resources. Other kinds of resources (JS, Java, etc) can be scoped to orgs and environments and you can use the Management API to achieve those scopes (not through the UI though).
To elaborate on what my colleagues propose.
Not that I know of. But personally, I'd prefer not sharing modules among multiple API proxies because managing versions could lead to dependency hell. Instead, I'd recommend leveraging a build tool (Grunt or Maven) for resolving NPM dependencies per proxy; in coordination with apigeetool capabilities to upload modules and a headless way or CLI. You can take a look at this post to checkout how other users leverage apigeetool to --upload-modules.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |