Best way to identify the path to the application

Not applicable

On EDGE we have a node.js which is now almost working with the help of @Scott Ganyo

We have the following which does not work due to the relative path points to the root of our edge, not to the root of our app:

module.exports = function(app) { 
  app.post('/xxx/yyy', yyy); 
  app.get('/xxx/zzz', zzz); 
};

The above maps to

http://ourdomain.apigee.com/xxx

instead of

http://ourdomain.apigee.com/ourproxyname/xxx

So do we need something like an environment var - if yes, how to set such a thing, or is there a better way?

module.exports = function(app) { 
  var root = process.env.APIGEE_PROXY; 
  app.post(root + '/xxx/yyy', yyy); 
  app.get(root + '/xxx/zzz', zzz); 
};

UPDATE:

We solved it by NOT giving the NAME of the widget in the base path -b when uploading it with the apigeeTool

1 5 1,217
5 REPLIES 5

Not applicable

Hi .. Did you find the answer .. I have similar issues

@jsmiles - see my reply here: https://community.apigee.com/answers/13048/view.html

also, @mplungjan , you too, of course.

Please see update. We were just giving too much info on the command line when uploading.

I'm not sure you need what you're asking for. I don't have the same file structure as your app does, maybe you could share it. But I tried something simple, and it works just fine without knowing , a priori, the proxy basepath. I'm using express 4.12 and apigee-access 1.3.0. My package.json looks like this:

{
  "name": "node-demo1",
  "description": "demonstration of retrieving flow variable within a request",
  "version": "0.0.2",
  "main": "express-server.js",
  "author" : { "name" : "Dino Chiesa"},
  "scripts": {
    "start": "node express-server.js",
    "test": "echo \"Whoops: there are no tests\" && exit 1"
  },
  "license": "MIT",
  "dependencies": {
    "apigee-access" : "1.3.0",
    "express": "4.12.3",
    "body-parser" : "1.12.3"
  },
  "engines": {
    "node": "0.10.x",
    "npm": "2.8.x"
  }
}

And this app code:

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var apigee = require('apigee-access');
var env = process.env;

app.use(bodyParser.json());

app.use("/about", function(req, res, next) {
  var message = { "route" : 1 };
  message['path-in-apigee'] = apigee.getVariable(req, 'request.path') || "unknown";
  message['express-baseUrl'] = req.baseUrl;
  res.json(message);
});

// catch 404
app.use(function(req, res, next) {
  var payload = { message: "Not found" };
  res.status(404);
  res.json(payload);
});

app.listen(process.env.PORT | 8124, function() {
  var host = server.address().address;
  var port = server.address().port;
  console.log('listening at http://%s:%s', host, port);
});

Note the "app.use" references a path "/about".

When I send in a request like this:

curl -i http://ORGNAME-ENVNAME.apigee.net/node-pathsuffix/about

I get this json response:

{
    "express-baseUrl": "/about",
    "path-in-apigee": "/node-pathsuffix/about",
    "route": 1
}

Thanks for the answer. We solved very simply by NOT giving the FULL name of the widget to the base path -b when uploading it with the apigeeTool