You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
// Custom Next.js server with extended timeout for video generation
|
|
// Node.js default server.requestTimeout is 5 minutes (300,000ms)
|
|
// We extend it to 10 minutes for long-running fal.ai video generation
|
|
|
|
const { createServer } = require('http');
|
|
const next = require('next');
|
|
|
|
const dev = process.env.NODE_ENV !== 'production';
|
|
const hostname = process.env.HOSTNAME || '0.0.0.0';
|
|
|
|
function getConfiguredPort() {
|
|
const portArgIndex = process.argv.findIndex((arg) => arg === '--port' || arg === '-p');
|
|
const positionalPort = process.argv.slice(2).find((arg) => /^\d+$/.test(arg));
|
|
const configuredPort = portArgIndex >= 0 ? process.argv[portArgIndex + 1] : process.env.PORT || positionalPort;
|
|
const port = Number(configuredPort ?? 3000);
|
|
|
|
return Number.isInteger(port) && port >= 0 ? port : 3000;
|
|
}
|
|
|
|
const port = getConfiguredPort();
|
|
const publicUrl = process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${port}`;
|
|
|
|
const app = next({ dev, hostname, port });
|
|
const handle = app.getRequestHandler();
|
|
|
|
app.prepare().then(() => {
|
|
const server = createServer(async (req, res) => {
|
|
await handle(req, res);
|
|
});
|
|
|
|
// Increase timeout to 10 minutes for long-running video generation
|
|
server.requestTimeout = 600000; // 10 minutes
|
|
server.headersTimeout = 610000; // Slightly longer than requestTimeout
|
|
|
|
server.listen(port, () => {
|
|
console.log(`> Ready on ${publicUrl}`);
|
|
console.log(`> Listening on http://${hostname}:${port}`);
|
|
console.log(`> Server timeout set to ${server.requestTimeout / 1000 / 60} minutes`);
|
|
});
|
|
});
|
|
|