diff --git a/.changeset/blue-glasses-hug.md b/.changeset/blue-glasses-hug.md new file mode 100644 index 000000000000..c173e77d7d61 --- /dev/null +++ b/.changeset/blue-glasses-hug.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/adapter-node": minor +--- + +feat: ability to create writable sockets diff --git a/documentation/docs/25-build-and-deploy/40-adapter-node.md b/documentation/docs/25-build-and-deploy/40-adapter-node.md index 0a7c553c4acc..e738f1cfa26c 100644 --- a/documentation/docs/25-build-and-deploy/40-adapter-node.md +++ b/documentation/docs/25-build-and-deploy/40-adapter-node.md @@ -60,7 +60,7 @@ If you use Node.js v20.6+, you can use the [`--env-file`](https://nodejs.org/en/ node +++--env-file=.env+++ build ``` -### `PORT`, `HOST` and `SOCKET_PATH` +### `PORT`, `HOST`, `SOCKET_PATH` and `SOCKET_PATH_IS_WRITABLE` By default, the server will accept connections on `0.0.0.0` using port 3000. These can be customised with the `PORT` and `HOST` environment variables: @@ -74,6 +74,13 @@ Alternatively, the server can be configured to accept connections on a specified SOCKET_PATH=/tmp/socket node build ``` +By default, node will create a socket based on the `umask` (commonly `0022`, resulting in `0755`). When `SOCKET_PATH_IS_WRITABLE` is set to `1`, the socket will be created with `0777`. + +``` +SOCKET_PATH_IS_WRITABLE=1 SOCKET_PATH=/tmp/socket node build +``` + + ### `ORIGIN`, `PROTOCOL_HEADER`, `HOST_HEADER`, and `PORT_HEADER` HTTP doesn't give SvelteKit a reliable way to know the URL that is currently being requested. The simplest way to tell SvelteKit where the app is being served is to set the `ORIGIN` environment variable: diff --git a/packages/adapter-node/src/env.js b/packages/adapter-node/src/env.js index b8e44ee0c7f5..0db6a3aac0d9 100644 --- a/packages/adapter-node/src/env.js +++ b/packages/adapter-node/src/env.js @@ -3,6 +3,7 @@ import process from 'node:process'; const expected = new Set([ 'SOCKET_PATH', + 'SOCKET_PATH_IS_WRITABLE', 'HOST', 'PORT', 'ORIGIN', diff --git a/packages/adapter-node/src/index.js b/packages/adapter-node/src/index.js index ef1ab701a2a3..3574936db950 100644 --- a/packages/adapter-node/src/index.js +++ b/packages/adapter-node/src/index.js @@ -4,6 +4,7 @@ import { env } from 'ENV'; import polka from 'polka'; export const path = env('SOCKET_PATH', false); +const writableAll = parseInt(env('SOCKET_PATH_IS_WRITABLE', 0)) === 1; export const host = env('HOST', '0.0.0.0'); export const port = env('PORT', !path && '3000'); @@ -38,7 +39,7 @@ if (socket_activation) { console.log(`Listening on file descriptor ${SD_LISTEN_FDS_START}`); }); } else { - server.listen({ path, host, port }, () => { + server.listen({ path, host, port, writableAll }, () => { console.log(`Listening on ${path || `http://${host}:${port}`}`); }); }