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!