mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 11:30:01 -04:00
Test Windows support again
This commit is contained in:
parent
0434e55c69
commit
34e923dea5
1 changed files with 20 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { readFile, writeFile, unlink, mkdir, rm } from 'node:fs/promises';
|
import { readFile, writeFile, unlink, mkdir, rm } from 'node:fs/promises';
|
||||||
import { exec, spawn } from 'node:child_process';
|
import { exec, fork } from 'node:child_process';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { build } from 'esbuild';
|
import { build } from 'esbuild';
|
||||||
|
|
||||||
|
@ -26,19 +26,34 @@ for(let i = 2; i < process.argv.length; i++)
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
});
|
});
|
||||||
|
else if (process.platform === "win32")
|
||||||
|
exec("START", ["/B", "node", "backend.js"], (error, stdout) => {
|
||||||
|
if (error) throw error;
|
||||||
|
console.log(stdout);
|
||||||
|
});
|
||||||
else {
|
else {
|
||||||
const server = spawn("node",
|
const server = fork(fileURLToPath(new URL("./backend.js", import.meta.url)),
|
||||||
[fileURLToPath(new URL("./backend.js", import.meta.url))],
|
{detached: true}
|
||||||
{cwd: process.cwd(), stdio: "inherit", detached: true}
|
|
||||||
);
|
);
|
||||||
server.unref();
|
server.unref();
|
||||||
|
server.disconnect();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "stop":
|
case "stop":
|
||||||
await writeFile(shutdown, "");
|
await writeFile(shutdown, "");
|
||||||
try {await fetch(new URL("/test-shutdown", serverUrl))}
|
try {
|
||||||
|
const response = await Promise.race([
|
||||||
|
fetch(new URL("/test-shutdown", serverUrl)),
|
||||||
|
new Promise(resolve => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve("Error");
|
||||||
|
}, 5000);
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
if(response === "Error") throw new Error("Server is unresponsive.");
|
||||||
|
}
|
||||||
catch (e) {await unlink(shutdown)}
|
catch (e) {await unlink(shutdown)}
|
||||||
if (config.production)
|
if (config.production)
|
||||||
exec("npm run pm2-stop", (error, stdout) => {
|
exec("npm run pm2-stop", (error, stdout) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue