Skip to content

Commit 0e09581

Browse files
tsanthRich-Harris
andauthored
Makes Node adapter respect HOST (#1365) (#1366)
* Makes Node adapter respect HOST (#1365) By default, the HOST variable is set to 127.0.0.1, for safety. * Node adapter defaults to all interfaces for prod (#1366) * Fixes code formatting * changeset * add docs and license * document env vars * we decided against this Co-authored-by: Rich Harris <[email protected]>
1 parent d31eb66 commit 0e09581

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

.changeset/tricky-walls-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-node': patch
3+
---
4+
5+
Make host configurable via process.env.HOST

packages/adapter-node/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

packages/adapter-node/README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
1-
# adapter-node
1+
# @sveltejs/adapter-node
22

3-
Adapter for Svelte apps that builds a Node server — the equivalent of `sapper build`.
3+
[Adapter](https://kit.svelte.dev/docs#adapters) for SvelteKit apps that generates a standalone Node server.
44

5-
This is very experimental; the adapter API isn't at all fleshed out, and things will definitely change.
5+
## Usage
6+
7+
Install with `npm i -D @sveltejs/adapter-node@next`, then add the adapter to your `svelte.config.js`:
8+
9+
```js
10+
// svelte.config.js
11+
import adapter from '@sveltejs/adapter-node';
12+
13+
export default {
14+
kit: {
15+
adapter: adapter({
16+
// default options are shown
17+
out: 'build'
18+
})
19+
}
20+
};
21+
```
22+
23+
## Options
24+
25+
### out
26+
27+
The directory to build the server to. It defaults to `build` — i.e. `node build` would start the server locally after it has been created.
28+
29+
## Environment variables
30+
31+
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:
32+
33+
```
34+
HOST=127.0.0.1 PORT=4000 node build
35+
```
36+
37+
## License
38+
39+
[MIT](LICENSE)

packages/adapter-node/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { createServer } from './server';
22
/*eslint import/no-unresolved: [2, { ignore: ['\.\/app\.js$'] }]*/
33
import * as app from './app.js';
44

5-
const { PORT = 3000 } = process.env; // TODO configure via svelte.config.js
5+
const { HOST = '0.0.0.0', PORT = 3000 } = process.env;
66

7-
const instance = createServer({ render: app.render }).listen(PORT, (err) => {
7+
const instance = createServer({ render: app.render }).listen(PORT, HOST, (err) => {
88
if (err) {
99
console.log('error', err);
1010
} else {

0 commit comments

Comments
 (0)