I have a website built with reactjs front-end and express server as back-end, communicating over http. Now I need to switch to https. Where do I need to make changes?
My understanding is that I mostly need to change the express server and in the front-end to only switch urls to https://url. I implemented standard express https server configuration.
Bellow is my express server code:
const express = require('express')
const fs = require('fs')
const https = require('https')
const cors = require('cors')
const bodyParser = require('body-parser')
const passport = require('passport')
const localSignupStrategy = require('./passport/local-signup')
const localLoginStrategy = require('./passport/local-login')
const authRoutes = require('./routes/auth')
const productsRoutes = require('./routes/products')
const path = require('path')
// db
let env = process.env.NODE_ENV || 'development'
let settings = require('./config/settings')[env]
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(passport.initialize())
app.use(cors())
// db
require('./config/database')(settings)
passport.use('local-signup', localSignupStrategy)
passport.use('local-login', localLoginStrategy)
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next()
})
app.use(express.static(path.join(__dirname, '../public')))
// routes
app.use('/auth', authRoutes)
app.use('/products', productsRoutes)
let options = {
key: fs.readFileSync('privatekey.pem'),
cert: fs.readFileSync('certificate.pem')
}
https.createServer(options, app).listen(settings.httpsPort, () => {
console.log(`Server running on port ${settings.httpsPort}...`)
})
When testing locally I get this error:
"Failed to load resource: net::ERR_CONNECTION_REFUSED"
when making my server calls and I'm lost on what that's telling me exactly. I am not sure if it is the certificates, server config or the react client and I'm generally lost on how to think about solving the problem.
Any guidance would be appreciated.