parcel-bundler / parcel

The zero configuration build tool for the web. πŸ“¦πŸš€
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

Parcel 2: `parcel watch` doesn't respect `--cert` or `--key` flags #4485

Open bentruyman opened 4 years ago

bentruyman commented 4 years ago

πŸ› bug report

parcel watch doesn't appear to use the --cert or --key flags, though its help output states it supports them. I don't know that the --https flag is affecting anything either.

Not sure if this is related to the recent work done in #4417.

πŸ€” Expected Behavior

$ parcel serve --cert cert.pem --key key.pem index.html
$ parcel watch --cert cert.pem --key key.pem index.html

Both of the above commands should result in an HMR server starting up on the default port, in "HTTPS mode", using the specified cert and private key.

😯 Current Behavior

When running the following:

$ parcel serve --cert cert.pem --key key.pem index.html

Parcel starts up an HTTPS HMR server on port 1234 using the certificate and private key specified.

parcel watch also states it supports the --cert and --key flags. However, when running the following:

$ parcel watch --cert cert.pem --key key.pem index.html

A non-HTTPS HMR server is started up.

πŸ’ Possible Solution

πŸ”¦ Context

Being able to specify a custom cert for watch is beneficial in the same ways it is for build. For example, it lets one setup local environments testing with E2E TLS encryption, while still allowing the convenience of Parcel's great HMR support.

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.220
Node 12.16.2
npm/Yarn Yarn 1.22.0
Operating System macOS 10.15.4
mischnic commented 4 years ago

The HMROptions should include https as well (just like the ˚ServerOptions` do). https://github.com/parcel-bundler/parcel/blob/c8d127623e419f23b6216d3fc68e1d45adeecbd0/packages/core/parcel/src/cli.js#L287-L301

Then it needs to be passed to the server as well here (currently via ...serve): https://github.com/parcel-bundler/parcel/blob/c8d127623e419f23b6216d3fc68e1d45adeecbd0/packages/reporters/dev-server/src/ServerReporter.js#L27-L40

(Used here: https://github.com/parcel-bundler/parcel/blob/c8d127623e419f23b6216d3fc68e1d45adeecbd0/packages/reporters/dev-server/src/Server.js#L346 )

parulc7 commented 4 years ago

Is this issue up for grabs? If yes, I would love to contribute.

mischnic commented 4 years ago

Sure! @parulc7

windware-ono commented 2 years ago

How can I make HMR work if I run a site under https:// but parcel never runs in HTTPS mode for watch?

Within the browser, it tries to connect with wss but apparently, watch mode doesn't speak HTTPS and I also cannot have SSL termination from a reverse proxy on the host when --host doesn't seem to work to bind to a specific IP but always listens on all interfaces making it impossible for a reverse proxy to listen to the same port to proxy to parcel with plain HTTP protocol.

Adding --hmr-connect option as I've explained in another issue seems to solve these problems.

hirasso commented 2 years ago

I am also having problems with valid HTTPSOptions in my ServerOptions, https and the injected wss WebSocket not connecting (Status in my Network tab is Finished)

Casburggraaf commented 1 year ago

I still have this problem, when using "--https" and/or "--cert PATH --key PATH" on parcel2 its not connection with wws. I can still connect with ws:// (see screenshot)

image

parcel watch --https --cert ~/cert.pem --key ~/key.pem"