Skip to content

Commit e7880a2

Browse files
committed
wiiiip
1 parent cb67837 commit e7880a2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/node/app.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import http from "http"
66
import * as httpolyglot from "httpolyglot"
77
import * as util from "../common/util"
88
import { DefaultedArgs } from "./cli"
9+
import { isNodeJSErrnoException } from "./util"
910
import { handleUpgrade } from "./wsRouter"
1011

1112
/**
@@ -39,9 +40,11 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, Express,
3940
if (args.socket) {
4041
try {
4142
await fs.unlink(args.socket)
42-
} catch (error) {
43-
if (error.code !== "ENOENT") {
43+
} catch (error: any) {
44+
if (isNodeJSErrnoException(error) && error.code !== "ENOENT") {
4445
logger.error(error.message)
46+
} else if (!isNodeJSErrnoException(error)) {
47+
logger.error(error)
4548
}
4649
}
4750
server.listen(args.socket, resolve)

src/node/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,10 @@ export function escapeHtml(unsafe: string): string {
524524
.replace(/"/g, "&quot;")
525525
.replace(/'/g, "&apos;")
526526
}
527+
528+
/**
529+
*
530+
*/
531+
export function isNodeJSErrnoException(error: unknown): error is NodeJS.ErrnoException {
532+
return error instanceof Error && (error as NodeJS.ErrnoException).code !== undefined
533+
}

test/unit/node/app.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,15 @@ describe("handleServerError", () => {
159159
expect(spy).toThrowErrorMatchingSnapshot()
160160
})
161161
})
162+
163+
164+
// TODO@jsjoeio - write
165+
// make a file owned by root
166+
// restrictive permissions - 600
167+
// no one else can touch it besides root
168+
169+
// make the socket on the file path and i'll get that..
170+
171+
// pass in / into
172+
// create a directory and pass that in as the socket
173+
// with one file and use the directory as the socket path

0 commit comments

Comments
 (0)