Security fixes pass #2
This commit is contained in:
Vendored
+12
@@ -1,6 +1,9 @@
|
||||
import { Command } from "commander";
|
||||
import path from "path";
|
||||
import writeErrorFile from "../../functions/write-error-file";
|
||||
let retries = 0;
|
||||
let timeout;
|
||||
const MAX_RETRIES = 5;
|
||||
export default function () {
|
||||
return new Command("start")
|
||||
.description("Start production server")
|
||||
@@ -9,6 +12,11 @@ export default function () {
|
||||
});
|
||||
}
|
||||
async function start() {
|
||||
clearTimeout(timeout);
|
||||
if (retries >= MAX_RETRIES) {
|
||||
console.error(`Production server crashed ${MAX_RETRIES} times. Exiting.`);
|
||||
process.exit(1);
|
||||
}
|
||||
const dev_spawn_file = path.resolve(__dirname, "prod-spawn.ts");
|
||||
const spawn_options = {
|
||||
cmd: ["bun", dev_spawn_file],
|
||||
@@ -22,6 +30,10 @@ async function start() {
|
||||
},
|
||||
};
|
||||
let dev_process = Bun.spawn(spawn_options);
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
}, 10000);
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
return await start();
|
||||
|
||||
Reference in New Issue
Block a user