'var baseUrl = app.get'url'replace/ \ / $ /,'';'中的'url'在哪里?'来自Loopback 3?

问题描述

app.start = function() {
  // start the web server
  return app.listen(function() {
    app.emit('started');
    var baseUrl = app.get('url').replace(/\/$/,'');
    console.log('Web server listening at: %s',baseUrl);
    if (app.get('loopback-component-explorer')) {
      var explorerPath = app.get('loopback-component-explorer').mountPath;
      console.log('browse your REST API at %s%s',baseUrl,explorerPath);
    }
  });
};

我正在尝试将Cloud Foundry应用程序(使用Loopback 3)路由到上下文路径host.domain.com/this-path

首先,仅使用cf create-routecf map-route无效。我会收到404错误,因此我在Loopback应用中将root.js更改为包含this-path.

'use strict';

module.exports = function(server) {
  // Install a `/` route that returns server status
  var router = server.loopback.Router();
  router.get('/this-path',server.loopback.status());
  server.use(router);
};

它能够在host.domain.com/this-path处获得回送状态,但是API调用/附加路径将无法工作,我只会遇到这样的错误。因此,然后我尝试更改Loopback config.json的restApiRoot以同时包含路径,但这也给了我这样的错误

"error": {
        "statusCode": 404,"name": "Error","message": "Cannot POST /this-path/api/make-something","status": 404,"stack": "Cannot POST /this-path/api/make-something\n    at raiseUrlNotFoundError (/home/vcap/app/node_modules/loopback/server/middleware/url-not-found.js:21:17)\n    at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/home/vcap/app/node_modules/express/lib/router/index.js:317:13)\n    at /home/vcap/app/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/home/vcap/app/node_modules/express/lib/router/index.js:335:12)\n    at next (/home/vcap/app/node_modules/express/lib/router/index.js:275:10)\n    at /home/vcap/app/node_modules/express/lib/router/index.js:635:15\n    at next (/home/vcap/app/node_modules/express/lib/router/index.js:260:14)\n    at Function.handle (/home/vcap/app/node_modules/express/lib/router/index.js:174:3)\n    at router (/home/vcap/app/node_modules/express/lib/router/index.js:47:12)\n    at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/home/vcap/app/node_modules/express/lib/router/index.js:317:13)\n    at /home/vcap/app/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/home/vcap/app/node_modules/express/lib/router/index.js:335:12)\n    at next (/home/vcap/app/node_modules/express/lib/router/index.js:275:10)\n    at nosniff (/home/vcap/app/node_modules/dont-sniff-mimetype/index.js:4:5)"
    }
}

所以现在我想知道url中的var baseUrl = app.get('url').replace(/\/$/,'');来自哪里,我可以更改它,以便我的应用在host.domain.com/this-path?上监听

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...