Skip to content

Commit

Permalink
fix: dev server 503 HTTP error on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
datismoa committed Jun 20, 2023
1 parent 20078be commit 764a4be
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/dev/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Worker } from "node:worker_threads";
import { existsSync, promises as fsp } from "node:fs";
import { existsSync, accessSync, promises as fsp } from "node:fs";
import { debounce } from "perfect-debounce";
import {
App,
Expand Down Expand Up @@ -99,6 +99,18 @@ async function killWorker(worker: NitroWorker, nitro: Nitro) {
}
}

const tryAccessSync = (path) => {
try {
accessSync(path)

return true
}

catch {
return false
}
}

export function createDevServer(nitro: Nitro): NitroDevServer {
// Worker
const workerEntry = resolve(
Expand Down Expand Up @@ -190,7 +202,7 @@ export function createDevServer(nitro: Nitro): NitroDevServer {
eventHandler(async (event) => {
await reloadPromise;
const address = currentWorker && currentWorker.address;
if (!address || (address.socketPath && !existsSync(address.socketPath))) {
if (!address || (address.socketPath && !tryAccessSync(address.socketPath))) {
return errorHandler(lastError, event);
}
await proxy.handle(event, { target: address }).catch((err) => {
Expand Down

0 comments on commit 764a4be

Please sign in to comment.