H12 HEROKU错误在使用Axios提出后并进行反应
我已经制作了我在NetLify上托管的React.js应用程序,该应用程序将POST请求发送到Heroku上托管的Node.js服务器。每当我发送发布请求时,它都会暂时工作,但是30秒后,它会发送H12错误。我尝试了所有事情,但似乎没有任何作用。我客户端的链接是在这里。我的服务器代码如下:
const express = require('express');
const db = require("./config/db");
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path');
const PORT = 3001;
const timeout = require('connect-timeout');
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "https://coruscating-dolphin-7548e8.netlify.app");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use(express.json())
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, "..", "build")));
app.use(express.static("public"));
app.post('/api/test', timeout('2s', {respond: false}), cors(), (req, res) => {
console.log("test");
console.log(req.body.test);
});
app.listen(process.env.PORT || PORT, () => {
console.log(`running on port ${PORT}`);
});
在这里,它在Heroku:
2022-04-24T23:02:29.132724+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/api/test" host=word-data-database.herokuapp.com request_id=2c39695c-e8ec-47c2-9940-e85ec3ccd450 fwd="65.189.245.250" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
注意:我有帖子并获得了使用我的数据库的帖子,但是我将它们切掉以测试它们是否是问题的,但事实并非如此。 任何帮助将不胜感激!
I've made a React.JS app, which I've hosted on Netlify, which sends POST requests to a Node.JS server hosted on Heroku. Whenever I send a POST request, it works temporarily, but 30 seconds later it sends an H12 error. I've tried everything but nothing has seemed to work. The link to my client is here. My server code is the following:
const express = require('express');
const db = require("./config/db");
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path');
const PORT = 3001;
const timeout = require('connect-timeout');
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "https://coruscating-dolphin-7548e8.netlify.app");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use(express.json())
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, "..", "build")));
app.use(express.static("public"));
app.post('/api/test', timeout('2s', {respond: false}), cors(), (req, res) => {
console.log("test");
console.log(req.body.test);
});
app.listen(process.env.PORT || PORT, () => {
console.log(`running on port ${PORT}`);
});
Here is the error I keep getting in the browser.
And here it is in Heroku:
2022-04-24T23:02:29.132724+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/api/test" host=word-data-database.herokuapp.com request_id=2c39695c-e8ec-47c2-9940-e85ec3ccd450 fwd="65.189.245.250" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
Note: I had POSTs and GETs that used my database, but I cut them out to test if they were the problem, they weren't.
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论