Hello everyone,
I am using a node.js app as a hosted target in Apigee. The node app requires 2 command line arguments to be passed, which is done by the prompt module in the node app. When I use the app as a hosted target can I pass those arguments at runtime?(I know there is a way to pass it using the app.yaml file but I dont exactly know how). Also can I access these arguments in a JavaScript policy at runtime? I am working on Hosted Target for the first time so any leads on this topic would be very helpful. Thank you!
Solved! Go to Solution.
The node app requires 2 command line arguments to be passed, which is done by the prompt module in the node app. When I use the app as a hosted target can I pass those arguments at runtime?
I think maybe you might have to redesign the node app just a bit.
The prompt module, as I understand it, can be used by an interactive nodejs to prompt the user for some input.
There is no way to prompt the user for input in a Hosted Target. The HT node app is headless and serverless. You don't get to interact with the terminal that is running the HT node app. So I think prompt is probably the wrong module.
I know there is a way to pass it using the app.yaml file but I dont exactly know how
Pass parameters to the HT app via environment variables, as shown in the documentation.
can I access these arguments in a JavaScript policy at runtime?
No. And this question suggests you have a basic misunderstanding. You're passing arguments to the nodejs app. That app is remote. The JavaScript policy runs in the gateway; it's local. The JS policy doesn't have access to the remote nodejs app, nor to the environment variables or "parameters" you've passed to the remote nodejs app.
I am working on Hosted Target for the first time so any leads on this topic would be very helpful.
I would suggest starting with the documentation for Hosted Targets and within there, the sample apps.
Hi Manas,
You can find what you're looking for in the "args" key for the manifest file (from https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-reference#manfiest-file-syntax).
As far as accessing these in a JavaScript policy, you cannot access these variables as they are separate from the Hosted Target flow/configuration.
@Kyle Wiese Thank you for your directions Kyle!
The node app requires 2 command line arguments to be passed, which is done by the prompt module in the node app. When I use the app as a hosted target can I pass those arguments at runtime?
I think maybe you might have to redesign the node app just a bit.
The prompt module, as I understand it, can be used by an interactive nodejs to prompt the user for some input.
There is no way to prompt the user for input in a Hosted Target. The HT node app is headless and serverless. You don't get to interact with the terminal that is running the HT node app. So I think prompt is probably the wrong module.
I know there is a way to pass it using the app.yaml file but I dont exactly know how
Pass parameters to the HT app via environment variables, as shown in the documentation.
can I access these arguments in a JavaScript policy at runtime?
No. And this question suggests you have a basic misunderstanding. You're passing arguments to the nodejs app. That app is remote. The JavaScript policy runs in the gateway; it's local. The JS policy doesn't have access to the remote nodejs app, nor to the environment variables or "parameters" you've passed to the remote nodejs app.
I am working on Hosted Target for the first time so any leads on this topic would be very helpful.
I would suggest starting with the documentation for Hosted Targets and within there, the sample apps.
@Dino-at-Google Thank you for the answer. I will try working around this!
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |