我有一个通过req.params app.get('/someroute/:val' => res.send(req.params.val))传递一个值的路由。这个值实际上是一个经过编码的URL。
我可以通过localhost找到这条路由。但是,当我将其部署到Elastic-Beanstalk并尝试路由时,我得到一个404错误,指出找不到此路由。
我是不是遗漏了什么配置?
app.get('/someroute/:url', (req, res) => {
let uri = decodeURI(req.params.url);
Promise.all([reqFileOne.getRequest(), reqFileTwo.getRequest(uri)])
.then(d => res.json(d));
});我希望能够命中路由,并获得发送json响应,就像在我的本地计算机上所做的那样。
在AWS Elastic-Beanstalk上,不幸的是我得到了404分。
发布于 2019-05-23 13:21:44
在promise之前添加一些调试来输出uri的值,以检查它是否是您所期望的。
建议您使用decodeURIComponent而不是decodeURI,因为它被认为更可靠。在Elastic Beanstalk中,URI解码可能以未转义的字符结束,从而产生格式错误的URI,从而导致404。
app.get('/someroute/:url', (req, res) => {
let uri = decodeURIComponent(req.params.url);
Promise.all([reqFileOne.getRequest(), reqFileTwo.getRequest(uri)])
.then(d => res.json(d));
});如果您正在进行编码,那么您也应该使用encodeURIComponent而不是encodeURI。
https://stackoverflow.com/questions/56268154
复制相似问题