Skip to content

Commit 4740c62

Browse files
authored
[feat] allow node adapter to configure listen path (#2048)
1 parent da94af3 commit 4740c62

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

.changeset/eighty-waves-obey.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-node': patch
3+
---
4+
5+
[feat] allow node adapter to configure listen path

packages/adapter-node/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const pipe = promisify(pipeline);
2525
* out?: string;
2626
* precompress?: boolean;
2727
* env?: {
28+
* path?: string;
2829
* host?: string;
2930
* port?: string;
3031
* };
@@ -34,7 +35,7 @@ const pipe = promisify(pipeline);
3435
export default function ({
3536
out = 'build',
3637
precompress,
37-
env: { host: host_env = 'HOST', port: port_env = 'PORT' } = {},
38+
env: { path: path_env = 'SOCKET_PATH', host: host_env = 'HOST', port: port_env = 'PORT' } = {},
3839
esbuild: esbuildConfig
3940
} = {}) {
4041
/** @type {import('@sveltejs/kit').Adapter} */
@@ -57,7 +58,9 @@ export default function ({
5758
utils.copy(files, '.svelte-kit/node');
5859
writeFileSync(
5960
'.svelte-kit/node/env.js',
60-
`export const host = process.env[${JSON.stringify(
61+
`export const path = process.env[${JSON.stringify(
62+
path_env
63+
)}] || false;\nexport const host = process.env[${JSON.stringify(
6164
host_env
6265
)}] || '0.0.0.0';\nexport const port = process.env[${JSON.stringify(port_env)}] || 3000;`
6366
);

packages/adapter-node/src/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// TODO hardcoding the relative location makes this brittle
22
import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved
3-
import { host, port } from './env.js'; // eslint-disable-line import/no-unresolved
3+
import { path, host, port } from './env.js'; // eslint-disable-line import/no-unresolved
44
import { createServer } from './server';
55

66
init();
77

8-
const instance = createServer({ render }).listen(port, host, () => {
9-
console.log(`Listening on ${host}:${port}`);
8+
const instance = createServer({ render });
9+
10+
const listenOpts = { path, host, port };
11+
instance.listen(listenOpts, () => {
12+
console.log(`Listening on ${path ? path : host + ':' + port}`);
1013
});
1114

1215
export { instance };

0 commit comments

Comments
 (0)