mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 03:50:02 -04:00
New shutdown script for cross-platform ease of use; implement host option in config file; minor code cleanup.
This commit is contained in:
parent
c21d775ee8
commit
92909e4ab7
7 changed files with 59 additions and 10 deletions
21
shutdown.mjs
Normal file
21
shutdown.mjs
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { readFile, writeFile, unlink } from 'node:fs/promises';
|
||||
|
||||
const config = Object.freeze(JSON.parse(await readFile(new URL("./src/config.json", import.meta.url))));
|
||||
|
||||
const serverUrl = (base => {
|
||||
try {
|
||||
base = new URL(config.host);
|
||||
} catch (e) {
|
||||
base = new URL("http://a");
|
||||
base.host = config.host;
|
||||
}
|
||||
base.port = process.env.PORT || config.port;
|
||||
return Object.freeze(base);
|
||||
})();
|
||||
|
||||
const shutdown = new URL("./src/.shutdown", import.meta.url);
|
||||
|
||||
await writeFile(shutdown, "");
|
||||
try {await fetch(new URL("/test-shutdown", serverUrl))}
|
||||
catch (e) {await unlink(shutdown)}
|
||||
process.exitCode = 0;
|
Loading…
Add table
Add a link
Reference in a new issue