Skip to content

Commit 7aac0df

Browse files
committed
adapter-node - support writable sockets
Current the socket is created based on the umask (commonly `0022`), resulting in read only sockets. This change adds the env variable `SOCKET_PATH_IS_WRITABLE`, which configures `writableAll`, supporting writable sockets.
1 parent f451f6c commit 7aac0df

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

.changeset/blue-glasses-hug.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/adapter-node": minor
3+
---
4+
5+
feat: ability to create writable sockets

documentation/docs/25-build-and-deploy/40-adapter-node.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ If you use Node.js v20.6+, you can use the [`--env-file`](https://nodejs.org/en/
6060
node +++--env-file=.env+++ build
6161
```
6262

63-
### `PORT`, `HOST` and `SOCKET_PATH`
63+
### `PORT`, `HOST`, `SOCKET_PATH` and `SOCKET_PATH_IS_WRITABLE`
6464

6565
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:
6666

@@ -74,6 +74,13 @@ Alternatively, the server can be configured to accept connections on a specified
7474
SOCKET_PATH=/tmp/socket node build
7575
```
7676

77+
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`.
78+
79+
```
80+
SOCKET_PATH_IS_WRITABLE=1 SOCKET_PATH=/tmp/socket node build
81+
```
82+
83+
7784
### `ORIGIN`, `PROTOCOL_HEADER`, `HOST_HEADER`, and `PORT_HEADER`
7885

7986
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:

packages/adapter-node/src/env.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import process from 'node:process';
33

44
const expected = new Set([
55
'SOCKET_PATH',
6+
'SOCKET_PATH_IS_WRITABLE',
67
'HOST',
78
'PORT',
89
'ORIGIN',

packages/adapter-node/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { env } from 'ENV';
44
import polka from 'polka';
55

66
export const path = env('SOCKET_PATH', false);
7+
const writableAll = parseInt(env('SOCKET_PATH_IS_WRITABLE', 0)) === 1;
78
export const host = env('HOST', '0.0.0.0');
89
export const port = env('PORT', !path && '3000');
910

@@ -38,7 +39,7 @@ if (socket_activation) {
3839
console.log(`Listening on file descriptor ${SD_LISTEN_FDS_START}`);
3940
});
4041
} else {
41-
server.listen({ path, host, port }, () => {
42+
server.listen({ path, host, port, writableAll }, () => {
4243
console.log(`Listening on ${path || `http://${host}:${port}`}`);
4344
});
4445
}

0 commit comments

Comments
 (0)