在我的Apache配置中,我将所有流量转发/node
到3000
Express服务器正在侦听的端口。
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass /node http://localhost:3000/
</IfModule>
Express应用程序如下所示:
var express = require('express');
var app = express();
var router = express.Router();
router.route('/route/:id').get(function (req, res) {
res.json({ description: 'Welcome to a route with an ID' });
});
router.route('/route').get(function (req, res) {
res.json({ description: 'Welcome to the normal route' });
});
router.route('/').get(function (req, res) {
res.json({ data: 'Welcome to the app' });
});
app.use('/', router);
app.listen(3000);
当我将浏览器定向到http://myserver.com/node时,得到响应{ data: 'Welcome to the app' }
,这很好。但是,当我尝试进入http://myserver.com/node/route或http://myserver.com/node/1210时,出现错误Cannot GET //route
。
有什么想法可以更新Apache配置以保留Express路由吗?
我在CentOS上运行Apache 2.4.6。
您/
的主机结尾处还有多余的东西。尝试将其更改为:
ProxyPass /node http://localhost:3000
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句