简体   繁体   English

为什么我的 Express 服务器收到“404 cannot POST”错误?

[英]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.

相关问题 在我写得很好的(我认为)快递服务器上收到 404 错误 - Receiving a 404 error on my well-written (I think) express server 当我向 API 发送 POST 时,为什么会收到“帖子验证失败”错误? - Why am I receiving a "Posts validation failed" error when I am sending a POST to my API? 我正在尝试通过 express 为我的 React 应用程序提供服务,为什么我会收到 404? - I'm trying to serve my react app from express, why am I getting a 404? 来自 fetch 的发布请求会导致 404 服务器错误(javascript/express) - Post request from fetch gives a 404 server error (javascript/express) 无法 POST 到 Express 路由器(404 错误) - Cannot POST to Express router (404 error) 为什么我会收到“无法找到 null 的属性‘值’”错误? - Why am I receiving the “Cannot find property 'value' of null” error? 使用快速服务器的 POST 请求出现 404 错误 - 404 error with POST request using express server 为什么我从减速机 function 收到“NaN”? - Why am I receiving 'NaN' from my reducer function? 为什么我的本地node.js / express服务器的响应中没有得到JSON对象? - Why am I not getting a JSON object in the response from my local node.js/express server? 为什么我的 Javascript 收到 404 错误消息? - Why am I getting a 404 error message in my Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM