feat: increase server idle timeout and allow to modify it via env
This commit is contained in:
parent
f952532290
commit
1ce1e65271
2 changed files with 16 additions and 2 deletions
|
|
@ -4,17 +4,20 @@ import "dotenv/config";
|
|||
const envSchema = type({
|
||||
NODE_ENV: type.enumerated("development", "production", "test").default("production"),
|
||||
SERVER_IP: 'string = "localhost"',
|
||||
SERVER_IDLE_TIMEOUT: 'string.integer.parse = "60"',
|
||||
}).pipe((s) => ({
|
||||
__prod__: s.NODE_ENV === "production",
|
||||
environment: s.NODE_ENV,
|
||||
serverIp: s.SERVER_IP,
|
||||
serverIdleTimeout: s.SERVER_IDLE_TIMEOUT,
|
||||
}));
|
||||
|
||||
const parseConfig = (env: unknown) => {
|
||||
const result = envSchema(env);
|
||||
|
||||
if (result instanceof type.errors) {
|
||||
throw new Error(`Invalid environment variables: ${result.toString()}`);
|
||||
console.error(`Environment variable validation failed: ${result.toString()}`);
|
||||
throw new Error("Invalid environment variables");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { shutdown } from "./modules/lifecycle/shutdown";
|
|||
import { REQUIRED_MIGRATIONS } from "./core/constants";
|
||||
import { validateRequiredMigrations } from "./modules/lifecycle/checkpoint";
|
||||
import { createApp } from "./app";
|
||||
import { config } from "./core/config";
|
||||
|
||||
const app = createApp();
|
||||
|
||||
|
|
@ -33,4 +34,14 @@ process.on("SIGINT", async () => {
|
|||
process.exit(0);
|
||||
});
|
||||
|
||||
export default await createHonoServer({ app, port: 4096 });
|
||||
console.log(config.serverIdleTimeout);
|
||||
export default await createHonoServer({
|
||||
app,
|
||||
port: 4096,
|
||||
customBunServer: {
|
||||
idleTimeout: config.serverIdleTimeout,
|
||||
error(err) {
|
||||
logger.error(`[Bun.serve] Server error: ${err.message}`);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue