在我的 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 or http://myserver.com/node/1210我收到一个错误Cannot GET //route
.
有什么想法可以更新我的 Apache 配置以保留 Express 路由吗?
我在 CentOS 上运行 Apache 2.4.6。
你还有一个额外的/
在你的主机的末尾。尝试将其更改为:
ProxyPass /node http://localhost:3000
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)