Skip to content
Merged
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/eighty-waves-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

[feat] allow node adapter to configure listen path
7 changes: 5 additions & 2 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const pipe = promisify(pipeline);
* out?: string;
* precompress?: boolean;
* env?: {
* path?: string;
* host?: string;
* port?: string;
* };
Expand All @@ -34,7 +35,7 @@ const pipe = promisify(pipeline);
export default function ({
out = 'build',
precompress,
env: { host: host_env = 'HOST', port: port_env = 'PORT' } = {},
env: { path: path_env = 'SOCKET_PATH', host: host_env = 'HOST', port: port_env = 'PORT' } = {},
esbuild: esbuildConfig
} = {}) {
/** @type {import('@sveltejs/kit').Adapter} */
Expand All @@ -57,7 +58,9 @@ export default function ({
utils.copy(files, '.svelte-kit/node');
writeFileSync(
'.svelte-kit/node/env.js',
`export const host = process.env[${JSON.stringify(
`export const path = process.env[${JSON.stringify(
path_env
)}] || false;\nexport const host = process.env[${JSON.stringify(
host_env
)}] || '0.0.0.0';\nexport const port = process.env[${JSON.stringify(port_env)}] || 3000;`
);
Expand Down
9 changes: 6 additions & 3 deletions packages/adapter-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// TODO hardcoding the relative location makes this brittle
import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved
import { host, port } from './env.js'; // eslint-disable-line import/no-unresolved
import { path, host, port } from './env.js'; // eslint-disable-line import/no-unresolved
import { createServer } from './server';

init();

const instance = createServer({ render }).listen(port, host, () => {
console.log(`Listening on ${host}:${port}`);
const instance = createServer({ render });

const listenOpts = { path, host, port };
instance.listen(listenOpts, () => {
console.log(`Listening on ${path ? path : host + ':' + port}`);
});

export { instance };