question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Redirect all HTTP requests to HTTPS" plugin required

See original GitHub issue

Requested by @bennypowers in a separate thread:

One of the Lighthouse criteria is that the site redirects requests from http to https. Of course, I can set up rewrite according to the wiki page’s instructions, but that doesn’t give me the 302 Redirect I need to pass this audit. I’d very much like some feature like ws --server http2 --redirect-http-to-https which will take all requests and redirect them to https.

Could someone read this wiki page about extending ws and come up with something to achieve this?

This would be the typical use case - server one serves the main HTTPS app: (you’ll probably need admin privileges to serve on system ports like 443 and 80).

$ ws --https --port 443 

Server two catches stray HTTP traffic, loading a custom stack comprising your custom middleware (a local file called “redirect-everything.js” in this case) which returns the appropriate 302 response for each request received.

$ ws --port 80 --stack ./redirect-everything.js

It should be quite straight forward, not much code.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
bennypowerscommented, Mar 8, 2018

Ok the following configuration works:

lws.config.js

module.exports = {
  stack: [
    'lws-body-parser',
    'lws-request-monitor',
    'lws-log',
    'lws-compress',
    'lws-mock-response',
    'lws-static',
    'lws-cors',
  ],
  http2: true,
  port: 443,
  compress: true,
  mocks: 'restaurant-mocks.js',
  logFormat: 'combined',
};

lws.redirect.config.js

module.exports = {
  stack: ['redirect-everything'],
  port: 80,
  redirectPort: 443,
  logFormat: 'combined',
};

package.json

{
  "name": "mws-restaurant-stage-1",
  "version": "1.0.0",
  "description": "Project files for MWS Nanodegree",
  "main": "index.html",
  "dependencies": {
    "express": "^4.16.2",
    "local-web-server": "^2.5.0",
    "lws-compress": "^0.2.1",
    "lws-http2": "^0.2.2",
    "node": "^8.9.4"
  },
  "scripts": {
    "postinstall": "bower i --allow-root",
    "start": "npx ws & npx ws -c lws.redirect.config.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}

If i sudo npm start then I get the right behaviour

1reaction
75lbcommented, Jun 9, 2019

Resolved by the lws-redirect plugin.

Usage:

$ npm install --save-dev lws-redirect

$ lws --port 80 --stack lws-redirect --redirect 'http -> https'
Listening on http://mba4.local:80, http://127.0.0.1:80, http://192.168.0.200:80

$ $ curl -I http://127.0.0.1/
HTTP/1.1 302 Found
Location: https://127.0.0.1/
Content-Type: text/html; charset=utf-8
Content-Length: 67
Date: Sun, 09 Jun 2019 16:53:38 GMT
Connection: keep-alive
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Redirect HTTP to HTTPS in WordPress - Kinsta
No need to install a plugin or reach out to our support team, you can easily redirect all of your HTTP traffic to...
Read more >
Easy HTTPS Redirection (SSL) – WordPress plugin
The plugin allows an automatic redirection to the "HTTPS" version/URL of the site. Make your site SSL compatible easily.
Read more >
How to Force Redirect HTTP to HTTPS in WordPress? - Malcare
TL;DR: The quickest way to force your website over HTTPS is to install and activate the Really Simple SSL plugin. It works automatically,...
Read more >
How to Redirect Website from HTTP to HTTPS? - Geekflare
Go to Page Rules · Click “Create Page Rule” · Enter the URL (put the asterisk, so redirection happens for all the URI)...
Read more >
How to Redirect WordPress from HTTP to HTTPS
With the certificate in hand, you'll need to go into your WordPress site settings to change your URL over to HTTPS. Go into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found