Fix startup crash if the specified socket already exists

This commit is contained in:
TSR Berry 2023-07-18 13:09:39 +02:00
parent b0c43b3571
commit 700e913b6a
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2

View file

@ -1,10 +1,16 @@
import { env } from "process";
import { app, logger } from "./app";
import http from "http";
import { existsSync, rmSync } from "fs";
const server = http.createServer(app);
if (process.env.SOCKET_PATH != null && process.env.SOCKET_PATH.length > 0) {
// Remove the socket at the specified path if it already exists to avoid EADDRINUSE
if (existsSync(process.env.SOCKET_PATH)) {
rmSync(process.env.SOCKET_PATH);
}
server.listen({
path: process.env.SOCKET_PATH,
readableAll: true,