Parcel: Add option --host to development server, currently only localhost

Created on 22 May 2018  路  11Comments  路  Source: parcel-bundler/parcel

馃檵 feature request

The dev server should be able to listen on a non localhost interface. There should be a --host option to allow setting a different IP or 0.0.0.0 for all interfaces.

馃 Expected Behavior

When you start a dev server with parcel index.html --host 10.1.1.10 the dev server should listen on the 10.1.1.10 interface. (I guess also the websocket interface has to be changed in this case.)

When you start a dev server with parcel index.html --host 0.0.0.0 the dev server should listen on all interfaces.

When you omit the --host option, the dev server should only serve on localhost, like before. This is important for security reasons and backwards compatibility.

馃槸 Current Behavior

No --host option is possible and the dev server always listens on localhost. Some people believe it listens on 0.0.0.0 (which means 'listen on all interfaces/IPs') but this is not true. And it would be insecure.

馃拋 Possible Solution

Implement a --host option and pass its value to the http server. Probably in this file as second parameter after the port parameter:

https://github.com/parcel-bundler/parcel/blob/3988ffcf66033722c41d767e714ed1a01b572b27/src/Server.js#L103

I believe this needs also to be changed in the websocket server implementation:

https://github.com/parcel-bundler/parcel/blob/master/src/HMRServer.js

馃敠 Context

You won't need this if you only develop on your laptop / local machine.

This can be helpful if the development machine is a different machine in the same network, like a development VM. And there are special setups where you need it, see examples below.

馃捇 Examples

There can be situations like with vagrant or docker, or on continous integration servers or hosted web editors where you need to set a different interface. This has been mentioned in some other issues.

Another common situation is, when you are testing with a real phone as the client. Or if you develop on a lets say linux machine and want to see it live reloading on multiple parallel heads, like a windows machine with IE/Edge, a Mac, etc.

Many development servers have it:

Websocket

https://github.com/webpack/webpack-dev-server/blob/master/examples/cli/host-and-port/README.md#ipv4

npm run webpack-dev-server -- --open --port 5000 --host 0.0.0.0

Angular Cli

https://github.com/angular/angular-cli/#usage

ng serve --host 0.0.0.0 --port 4201

Vue.js CLI

https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#serve

vue-cli-service serve --host 0.0.0.0

Feature

Most helpful comment

I'd like to reopen this issue. The hmr-hostname option does not satisfy this request. For the purposes of CORS, I'd like to specify a specific host name that matches the access-control-allow-origin domain.

All 11 comments

reference #278
reference #924

reference #276

Hello, I'll be working on this issue this next couple of days. I'll be fixing some stuff in my PR and it should be ready.

Ok, the pull request should be ready :) and only requires approval PR

Ok, in the end I've closed the PR without merge given that the option --hmr-hostname seems to already do that this issue requests. Discussion

Closing. The dev server already listens on all interfaces by default.

I ran into this too and apparently I wasn't able to access the server from another device because port 1234 was not open on the host machine. So specifying 8080 did the trick. Posting here in case anyone else runs into this.

I'd like to reopen this issue. The hmr-hostname option does not satisfy this request. For the purposes of CORS, I'd like to specify a specific host name that matches the access-control-allow-origin domain.

@devongovett

Closing. The dev server already listens on all interfaces by default.

That does not seem to be true. It listens on localhost only by default. It even prints that to the console.
Ok the code just always prints out "localhost" not the real interface it bound too. Confusing.

./node_modules/.bin/vue-cli-service serve --host 0.0.0.0 --port 3000

I get "Invalid Host header"

I need to disablehostcheck
disableHostCheck: true flag
https://github.com/webpack/webpack-dev-server/issues/882

Is there a way to set it on the command line?

subscribing. this is major obstacle to running vue in a docker container.

I think this issue should be reopened. When running Parcel normally, it states the server is running on http://localhost:1234. However, whenever I try to connect, I can never get a connection to the server on my browser. I have to _explicitly_ state 0.0.0.0 to get the server bound to it and get a working connection.

Was this page helpful?
0 / 5 - 0 ratings