Skip to content

Commit eee708d

Browse files
authored
Merge pull request #171 from PepsRyuu/HostOption
Host option
2 parents 569c73b + d63bd61 commit eee708d

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

docs/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The following flags can be passed into Nollup CLI. You can find a full descripti
1919
* ```--port [port]```
2020
* ```--verbose```
2121
* ```--hmr-host [host]```
22+
* ```--host [host]```
2223
* ```--public-path [folder]```
2324
* ```--environment [variables]```
2425
* ```--https```

docs/dev-server.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The following options can be passed into Nollup Dev Server. You can find a full
3030
* ```Boolean verbose```
3131
* ```String headers```
3232
* ```String hmrHost```
33+
* ```String host```
3334
* ```String contentBase```
3435
* ```String publicPath```
3536
* ```Object proxy```

docs/options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This list provides a description of all of the options for the [CLI](./cli.md),
1515
| ```Boolean``` | ```verbose``` | Enable verbose logging. Default is ```false```. |
1616
| ```Object``` | ```headers``` | Provide custom headers for Express server responses. Useful to set cors headers for the server. |
1717
| ```String``` | ```hmrHost``` | Host to connect to for HMR. Default is ```window.location.host```. Useful for Electron environments. |
18+
| ```String``` | ```host``` | Specify the host to use. Default is ```localhost```. Useful for allowing remote connections, eg. ```0.0.0.0```|
1819
| ```Function``` | ```before``` | Receives Express app as argument. You can inject custom middleware before Nollup dev middleware. |
1920
| ```Function``` | ```after``` | Receives Express app as argument. You can inject custom middleware after Nollup dev middleware. |
2021
| ```Boolean``` | ```https``` | Enable https. Default is ```false```. Requires ```key``` and ```cert``` to be set |

lib/cli.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let options = {
2020
verbose: false,
2121
hmrHost: undefined,
2222
https: false,
23+
host: 'localhost'
2324
};
2425

2526
function getValue (index) {
@@ -111,6 +112,15 @@ for (let i = 0; i < process.argv.length; i++) {
111112
}
112113
break;
113114

115+
case '--host':
116+
value = getValue(i);
117+
if (value) {
118+
options.host = value;
119+
} else {
120+
throw new Error('Missing host for host option.');
121+
}
122+
break;
123+
114124
case '--https':
115125
options.https = true;
116126
break;

lib/dev-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ async function devServer(options) {
9494
app.use(fallback(entryPoint, { root: options.contentBase }));
9595
}
9696

97-
server.listen(options.port);
97+
server.listen(options.port, options.host || 'localhost');
9898

99-
console.log(`[Nollup] Listening on ${options.https ? 'https' : 'http'}://localhost:${options.port}`);
99+
console.log(`[Nollup] Listening on ${options.https ? 'https' : 'http'}://${options.host || 'localhost'}:${options.port}`);
100100
}
101101

102102
module.exports = devServer

0 commit comments

Comments
 (0)