【发布时间】:2015-02-03 21:08:44
【问题描述】:
我在本地构建了一个 strongloop loopback API 服务器,一切正常,但是当我将它上传到我的远程服务器时,SLC RUN 命令运行良好(我可以在终端中看到它实际上在 MySQL db 中创建了我的测试模型在同一台服务器上)但我无法访问 example.com/explorer 页面来查看 API...我是否需要配置不同的东西才能让它在远程服务器上工作?
我将端口从 3000 更改为 3001。这是我在服务器文件中的 config.json 文件。
{
"restApiRoot": "/api",
"host": "www.example.com",
"port": 3001,
"remoting": {
"context": {
"enableHttpContext": false
},
"rest": {
"normalizeHttpPath": false,
"xml": false
},
"json": {
"strict": false,
"limit": "100kb"
},
"urlencoded": {
"extended": true,
"limit": "100kb"
},
"cors": {
"origin": true,
"credentials": true
},
"errorHandler": {
"disableStackTrace": false
}
}
}
和引导目录中的资源管理器文件(是的,我确实运行了 npm install loopback-explorer)...
module.exports = function mountLoopBackExplorer(server) {
var explorer;
try {
explorer = require('loopback-explorer');
} catch(err) {
// Print the message only when the app was started via `server.listen()`.
// Do not print any message when the project is used as a component.
server.once('started', function(baseUrl) {
console.log(
'Run `npm install loopback-explorer` to enable the LoopBack explorer'
);
});
return;
}
var restApiRoot = server.get('restApiRoot');
var explorerApp = explorer(server, { basePath: restApiRoot });
server.use('/explorer', explorerApp);
server.once('started', function() {
var baseUrl = server.get('url').replace(/\/$/, '');
// express 4.x (loopback 2.x) uses `mountpath`
// express 3.x (loopback 1.x) uses `route`
var explorerPath = explorerApp.mountpath || explorerApp.route;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
});
};
【问题讨论】:
-
你的意思是 example.com:3001/explorer 对吧? (不是 example.com/explorer)或者是否有一些代理服务器通过您的节点实例?
-
是的,对不起,我的意思是 example.com:3001/explorer...任何想法为什么我会遇到这个问题?
-
您要连接的机器上的端口是否打开 (stackoverflow.com/questions/9609130/…)?它是 EC2 实例吗?
-
您有任何错误吗?堆栈跟踪?您的远程服务器有什么不同?端口开放了吗?
-
不,我已经在专用服务器上构建了它,并在我的 mac 上执行以下命令返回 1:nc ip port
标签: javascript node.js loopbackjs strongloop