[英]ExpressJS cannot get /route in Openshift, but locally it is working
My project have this following structure. 我的项目具有以下结构。
server.js
/node_modules
/build
vendor.js
main.js
index.html
I'm using express, and AngularJS's ui-router
. 我正在使用express和AngularJS的ui-router
。
In server.js
I have this code: 在server.js
我有以下代码:
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/build/index.html');
});
And locally it is working if I pass localhost:8080/hellothere
, I get the correct page but when I've deployed, it doesn't. 如果我通过localhost:8080/hellothere
,则在localhost:8080/hellothere
,我得到正确的页面,但是在部署后却没有。
Within the application if use the links to navigate the routes run, the URL is modified to /hellothere
, but if I update the page or try to go straight to the absolute URL I get: 在应用程序中,如果使用链接导航运行路线,则将URL修改为/hellothere
,但是如果我更新页面或尝试直接访问绝对URL,则会得到:
Cannot GET /hellothere
I'm already have tryied put: 我已经试穿了:
app.get('/page1', function(req, res) {
res.sendFile(__dirname + '/build/index.html');
});
app.get('/page2', function(req, res) {
res.sendFile(__dirname + '/build/index.html');
});
...
And the behavior is the same of '/*'
. 行为与'/*'
相同。 Fine local, broke on cloud. 精细本地,在云上破裂。
Any idea what's happening here? 知道这里发生了什么吗?
And locally it is working if I pass
localhost:8080/hellothere
, I get the correct page but when I've deployed, it doesn't. 如果我通过localhost:8080/hellothere
,则在localhost:8080/hellothere
,我得到正确的页面,但是在部署后却没有。
The possible reason might be after deploying your base url might be domainname.com/appname
and your local code is for localhost:portNumber
not for localhost:portNumber/appname
可能的原因可能是在部署基本URL后可能是domainname.com/appname
并且本地代码是针对localhost:portNumber
而不是localhost:portNumber/appname
So modify your path to 因此,修改您的路径
app.get('/appname/hellothere', function(req, res) {
res.send("hellothere is working");
});
instead of 代替
app.get('/hellothere', function(req, res) {
res.send("hellothere is working");
});
To run it locally, now you will need localhost:portNumber/appname/hellothere
要在本地运行它,现在您需要localhost:portNumber/appname/hellothere
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.