Beacon24 / v0

4 stars 2 forks source link

Express-SSLify HTTPS enforcement breaks Localhost #22

Open Beacon24 opened 1 year ago

Beacon24 commented 1 year ago

In order to ensure proper security/SSL compliance, I installed the node package express-sslify to automatically convert all http requests for the app domain to https requests. This package is recommended by heroku, along with one other I could not figure out how to implement.

Everything is now working properly with the app hosted on heroku, and any requests to http://app.thebeaconnetwork.org are converted successfully to https://. The problem is, now when I try to run the app on my localhost I get the following error in my browser window:

Secure Connection Failed

An error occurred during a connection to localhost:3000. SSL received a record that exceeded the maximum permissible length.

Error code: SSL_ERROR_RX_RECORD_TOO_LONG

Any tips? I tried adding the following as way to not run the program locally but it did not work.

if (app.get("env") === "production") {
   app.use(enforce.HTTPS({ trustProtoHeader: true }));
}

Perhaps a clue, once this triggers, even if I uninstall with npm uninstall express-sslify and remove the relevant lines of code, I get the same error with local host, until I erase my browser data/history.

The relevant lines of code are in the index.js top-level file, lines 20, 21, 67, and 147-149.