Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support writable sockets #13317

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-glasses-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/adapter-node": minor
---

feat: ability to create writable sockets
9 changes: 8 additions & 1 deletion documentation/docs/25-build-and-deploy/40-adapter-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-node/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import process from 'node:process';

const expected = new Set([
'SOCKET_PATH',
'SOCKET_PATH_IS_WRITABLE',
'HOST',
'PORT',
'ORIGIN',
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-node/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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}`}`);
});
}
Expand Down
Loading