diff --git a/docs/content/2.deploy/1.node.md b/docs/content/2.deploy/1.node.md index afda272148..d08611e047 100644 --- a/docs/content/2.deploy/1.node.md +++ b/docs/content/2.deploy/1.node.md @@ -38,6 +38,7 @@ You can customize server behavior using following environment variables: - `NITRO_PORT` or `PORT` (defaults to `3000`) - `NITRO_HOST` or `HOST` +- `NITRO_SOCKET` - if provided (a path to the desired socket file) the service will be served over the provided UNIX socket. - `NITRO_SSL_CERT` and `NITRO_SSL_KEY` - if both are present, this will launch the server in HTTPS mode. In the vast majority of cases, this should not be used other than for testing, and the Nitro server should be run behind a reverse proxy like nginx or Cloudflare which terminates SSL. - `NITRO_SHUTDOWN` - Enables the graceful shutdown feature when set to `'true'`. If it's set to `'false'`, the graceful shutdown is bypassed to speed up the development process. Defaults to `'false'`. - `NITRO_SHUTDOWN_SIGNALS` - Allows you to specify which signals should be handled. Each signal should be separated with a space. Defaults to `'SIGINT SIGTERM'`. diff --git a/src/runtime/entries/node-server.ts b/src/runtime/entries/node-server.ts index 3ad8aa6e22..3ed6c48b90 100644 --- a/src/runtime/entries/node-server.ts +++ b/src/runtime/entries/node-server.ts @@ -21,8 +21,10 @@ const port = (destr(process.env.NITRO_PORT || process.env.PORT) || 3000) as number; const host = process.env.NITRO_HOST || process.env.HOST; +const path = process.env.NITRO_UNIX_SOCKET; + // @ts-ignore -const listener = server.listen(port, host, (err) => { +const listener = server.listen(path ? { path } : { port, host }, (err) => { if (err) { console.error(err); // eslint-disable-next-line unicorn/no-process-exit @@ -30,13 +32,17 @@ const listener = server.listen(port, host, (err) => { } const protocol = cert && key ? "https" : "http"; const addressInfo = listener.address() as AddressInfo; + if (typeof addressInfo === "string") { + console.log(`Listening on unix socket ${addressInfo}`); + return; + } const baseURL = (useRuntimeConfig().app.baseURL || "").replace(/\/$/, ""); const url = `${protocol}://${ addressInfo.family === "IPv6" ? `[${addressInfo.address}]` : addressInfo.address }:${addressInfo.port}${baseURL}`; - console.log(`Listening ${url}`); + console.log(`Listening on ${url}`); }); // Trap unhandled errors