Skip to content

Commit

Permalink
Merge pull request #18 from TSRBerry/fix/socket-issues
Browse files Browse the repository at this point in the history
Fix startup crash if the specified socket already exists
  • Loading branch information
marysaka committed Jul 18, 2023
2 parents b0c43b3 + 700e913 commit 41feb2c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 41feb2c

Please sign in to comment.