Tyler Brown
Tyler Brown

Reputation: 427

Serve a 'localhost' web client over https using npm

SOLVED: So the solution was actually straight forward. First, I went into webpack and added the '--https' flag. BUT because I was using a template from themeforest, the template-developer hardcoded in localhost:3003 to servefiles to. I simply searched for 3003 and found a single line of code in webpack.config which i changed to 'https://localhost:3003' and that was all i needed to do!!

I'm building a front-end client using angular. I'm running into issues when calling API's because the server requires all requests to be sent over https.

Right now when use 'npm start' my project runs on http://localhost:3003. How can I change this to https://localhost:3003?

I'm not experienced with server and SSL - so just trying to figure out the easiest way to do this during development.

I'm using angular and webpack server. Here's a look at my package.json

"tslint": "tslint",
"server:hmr": "npm run server -- --inline --hot",
"server": "webpack-dev-server --open --progress --profile --watch --port 3003",
"start": "npm run server",
"start:hmr": "npm run server:hmr"

UPDATE: still haven't figured this out. I'm running on webpack (not angular cli). The solutions i've tried so far such as adding -https flag or serve-https npm library haven't worked. Both options will load the files of my web app over https - but I get a 404 error "failed to load webpack.js"

Upvotes: 1

Views: 4242

Answers (2)

Ryan Tsui
Ryan Tsui

Reputation: 948

Running your webpack-dev-server with the https flag.

webpack-dev-server --open --https --progress --profile --watch --port 3003

Upvotes: 2

David Findlay
David Findlay

Reputation: 1356

Try serve-https, it's a simple HTTPS static file server: https://www.npmjs.com/package/serve-https

Upvotes: 0

Related Questions