Parcel: 馃檵 Allow to specify a hostname for hosted IDEs

Created on 15 Dec 2017  路  12Comments  路  Source: parcel-bundler/parcel

I use Cloud9 which is a hosted IDE site. They do some host/port mapping stuff so they want me to use an environment variable whenever I start a server. I understand that I can pass the $PORT variable to the -p argument, but there doesn't appear to be an argument for the host, or ip address which I could pass the $IP variable to.

馃拋 Possible Solution

npx parcel-bundler index.html -p $PORT -h $IP

Feature

Most helpful comment

I'm having the same issue here.
I'm using a smartphone to connect to the website over LAN and the HMR fails to establish the connection
because the WebSocket is connecting to the localhost instead of window.location.hostname.

I fixed this issue by forking parcel and changing this:
https://github.com/parcel-bundler/parcel/blob/0eb4487491fd70390697ad413aeac994fca4309c/src/builtins/hmr-runtime.js#L18
to:

var ws = new WebSocket('ws://' + window.location.hostname + ':{{HMR_PORT}}/');

All 12 comments

@jessehattabaugh - Please see #278 for further discussion. The default host aligns with the host that Cloud9 specifies in their docs, so parcel should "just work" in Cloud9 without specifying a host. If this is not the case, please reply and we'll work through a solution.

@brandon93s I'm having a similar issue, perhaps I'm missing something here. I work on a remote server (i.e. not localhost) and starting and accessing the parcel HMR by the remote IP/domain works, the trouble is the socket connection is looking for http://localhost:<ws-port> which means the only way I've been able to get it working is to point localhost in my hosts file to my remote.

I see. I had approached this from the perspective of the HTTP server and not the implications on the HMR socket. Will re-open for further investigation.

I'm having the same issue here.
I'm using a smartphone to connect to the website over LAN and the HMR fails to establish the connection
because the WebSocket is connecting to the localhost instead of window.location.hostname.

I fixed this issue by forking parcel and changing this:
https://github.com/parcel-bundler/parcel/blob/0eb4487491fd70390697ad413aeac994fca4309c/src/builtins/hmr-runtime.js#L18
to:

var ws = new WebSocket('ws://' + window.location.hostname + ':{{HMR_PORT}}/');

This seemed like a pretty quick fix for an issue that can cause a lot of headaches, opened #426 above thanks to @leonardosnt's comment.

Unfortunately, I still have an issue in Cloud9 at Amazon Web Services.

  • File src/client/index.html links to file src/client/index.js
  • File index.js should log some text to the console
  • Command to start server is parcel src/client/index.html -p 8080

Now, it's not possible to open the server by the URL given by Parcel console log - but with the one given by Cloud9 for view in a separate window.

But the following error appears:

bildschirmfoto 2018-01-04 um 22 09 06

I don't think this actually made it out in a release yet, unless you're specifically using master. Additionally, you'll need to specify both the port -p and hmr-port -h

Last release was 4 days ago, the code commits about 5 days ... mhm, maybe I am wrong, but I thought the code is already published.

It's not in the latest (1.4.1), so you'll need to pull from master

Mhm, wenn I install from parcel-bundler/parcel (master), I get the following error:

> node_modules/.bin/parcel src/index.html

module.js:471
    throw err;
    ^

Error: Cannot find module '../lib/cli'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/ubuntu/workspace/test-parcel/node_modules/parcel-bundler/bin/cli.js:6:7)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Closing. Should be fixed by #426.

Hello,

I am not able to make parcel work in cloud 9 out of the box. I am running:

parcel ./src/index.html --https --port $PORT --hmr-hostname $IP --no-hmr -d ./parcel

The error message from cloud 9:

You may be using the wrong PORT & IP for your server application.Try passing $PORT and $IP to properly launch your application.

I was looking for some sort of '--host' parameter which I could pass $IP. This is for the basic site, not hmr (I thought I read above that you needed --hmr-hostname to make it work). Using v1.6.2.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dsky1990 picture dsky1990  路  3Comments

Niggler picture Niggler  路  3Comments

davidnagli picture davidnagli  路  3Comments

donaldallen picture donaldallen  路  3Comments

davidnagli picture davidnagli  路  3Comments