[英]Why am I receiving "404 cannot POST" error from my Express server?
so i have an express server that i'm using to handle webhook updates.所以我有一个用于处理 webhook 更新的快速服务器。 i have it running on a port, and that port i have a server config for a ProxyPass at a subpage of a domain (domain.com/help/webhook).
我让它在一个端口上运行,并且该端口在域的子页面 (domain.com/help/webhook) 上有一个 ProxyPass 的服务器配置。
<Location /help/webhook>
ProxyPass http://localhost:PORT/
ProxyPassReverse http://localhost:PORT/
</Location>
and i can get the root route just fine (it'll send back a 200 response with some text).而且我可以很好地获得根路由(它会发回带有一些文本的 200 响应)。 but when i try to make a
POST
to the other route (domain.com/help/webhook/update) i get a 404 cannot POST //update
error back.但是当我尝试向另一条路线 (domain.com/help/webhook/update) 发送
POST
时,我收到 404 cannot POST //update
错误返回。 here's my code:这是我的代码:
require('dotenv').config();
let child_process = require('child_process'),
user = process.env.GITHUB_USER,
port = process.env.WEBHOOK_PORT;
let app = require('express')();
app.get('/', (req, res) => {
res.status(200).send('this is the cherwell app webhook endpoint. nothing to see here.');
});
app.post('/update', (req, res) => {
let sender = req.body.sender,
branch = req.body.ref;
console.log('request received');
if(branch.indexOf('master') > -1 && sender.login === user) {
child_process.exec('./deploy.sh', (err, stdout, stderr) => {
if(err) {
console.error(err);
return res.send(500);
} else {
console.log('success');
res.send(200);
}
});
}
});
app.listen(port);
in GitHub, setting up the webhook and delivering the payload, this is the response:在 GitHub 中,设置 webhook 并传送有效载荷,这是响应:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST //update</pre>
</body>
</html>
any idea what this issue might be?知道这个问题可能是什么吗? i wrote this from a tutorial on webhooks online, and it seemed simple enough though it being my first time deploying an app, i may be missing something either on the server configuration side or in my express code.
我是根据 webhooks 在线教程写的,虽然这是我第一次部署应用程序,但它看起来很简单,我可能在服务器配置端或我的 express 代码中遗漏了一些东西。 i dunno which.
我不知道哪个。
thanks for the help in advance!我在这里先向您的帮助表示感谢!
It seems that the URL that is being posted to is //update
rather than /update
.似乎要发布到的 URL 是
//update
而不是/update
。 You should add a trailing slash to your location argument.您应该在 location 参数中添加一个尾部斜杠。
From the docs on mod_proxy
:从
mod_proxy
上的文档:
If the first argument ends with a trailing /, the second argument should also end with a trailing /, and vice versa.
如果第一个参数以尾随 / 结尾,则第二个参数也应以尾随 / 结尾,反之亦然。 Otherwise, the resulting requests to the backend may miss some needed slashes and do not deliver the expected results.
否则,对后端产生的请求可能会错过一些需要的斜杠,并且不会交付预期的结果。
https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.