ExpressJS无法在Openshift中获取/路由,但在本地它可以工作
ExpressJS cannot get /route in Openshift, but locally it is working
我的项目有以下结构。
server.js
/node_modules
/build
vendor.js
main.js
index.html
我用的是express和AngularJS的ui-router
。
在server.js
中,我有这样的代码:
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/build/index.html');
});
在本地,如果我通过localhost:8080/hellothere
,它就起作用了,我会得到正确的页面,但当我部署好后,它就不会了。
在应用程序中,如果使用链接导航运行的路线,URL将修改为/hellothere
,但如果我更新页面或尝试直接转到我得到的绝对URL:
Cannot GET /hellothere
我已经试过了:
app.get('/page1', function(req, res) {
res.sendFile(__dirname + '/build/index.html');
});
app.get('/page2', function(req, res) {
res.sendFile(__dirname + '/build/index.html');
});
...
其行为与CCD_ 5相同。很好的本地,在云上破碎。
知道这里发生了什么吗?
同源网站链接
在本地它是有效的,如果我通过
localhost:8080/hellothere
,我得到正确的页面,但当我部署后,它没有。
可能的原因可能是在部署后,您的基本url可能是domainname.com/appname
,而您的本地代码是针对localhost:portNumber
而不是针对localhost:portNumber/appname
所以修改你的路径
app.get('/appname/hellothere', function(req, res) {
res.send("hellothere is working");
});
而不是
app.get('/hellothere', function(req, res) {
res.send("hellothere is working");
});
要在本地运行它,现在需要localhost:portNumber/appname/hellothere
相关文章:
- 节点J的路由不工作
- 路由不'我不在AngularJS工作
- 使用node/express在angular.js中不工作的路由
- 为什么获胜't此代码中的路由工作
- 无法获取用户 ID 路由参数以在反应路由器中继上工作
- 没有哈希“#”的 AngularJS 路由 - 无法让它工作
- AngularJS路由未按预期工作
- 节奏和余烬,我如何让它在所有路由中工作而不重复代码
- 如何在Microsoft IIS上使用反应路由器(createBrowserHistory)使路由工作
- AngularJs 路由不再工作.地址栏更改,但视图不会更改
- AngularJS 1.3 路由不工作;控制器从未调用
- 余烬与数据 - 路由模型无法一致地工作
- 在某些情况下,似乎无法让角度路由工作
- Cordova+AngularJs路由不工作
- ng路由工作不正常
- AngularJS+NodeJS路由-不工作
- 使主干路由正常工作
- 骨干JS路由没有像我预期的那样工作
- AngularJS路由不工作,但没有抛出任何错误
- Angularjs 路由无法正常工作