setupProxy中的超时在localhost中有效,但在dokku deployement应用程序中无效



我正在NodeJS和React中开发一个应用程序进行研究,我遇到了一个问题:

当我在localhost中使用我的应用程序时,我的长时间请求发布的超时(20/30分钟(有效(在setupProxy.js文件中写入(。但在部署在Dokku上的应用程序中,此超时不起作用(请求在1分钟后失败,错误为:">POST 504(网关超时("(。我认为Dokku默认情况下有一个超时,但我不确定,我也不知道如何修复它。

我的代码:

setupProxy.js

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
var port;
if (process.env.PORT) {
port = process.env.PORT;
} else {
port = 5000;
}
app.use(
createProxyMiddleware('/api/students', {
target: `http://localhost:${port}`,
timeout: 3840000,
})
);
app.use(
createProxyMiddleware('/api', {
target: `http://localhost:${port}`,
})
);
};

server.js

const express = require('express');
const connectDB = require('./config/db');
const path = require('path');
const app = express();
//Connect Database
connectDB();
//Set the limit  higher
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
//Define Routes
app.use('/api/users', require('./routes/api/users'));
app.use('/api/admins', require('./routes/api/admins'));
app.use('/api/auth', require('./routes/api/auth'));
app.use('/api/profile', require('./routes/api/profile'));
app.use('/api/students', require('./routes/api/students'));
app.use('/api/email', require('./routes/api/email'));
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
//Look on the heroku app for the port OR take de default port 5000
const PORT = process.env.PORT || 5000;
var server = app.listen(PORT, () =>
console.log(`Server started on port ${PORT}`)
);

提前感谢您的帮助!卡米尔。

Dokku使用nginx代理请求,我认为默认超时为60秒。

看起来这里有一个插件可以用来修改每个应用程序的超时。这也是直接向上游增加支持的一个很好的候选者。

相关内容

最新更新