syuji-higa
8/20/2019 - 11:19 AM

Node.js - reverse proxy

Node.js - reverse proxy

const https = require('https')
const fs = require('fs')
const express = require('express')
const proxy = require('express-http-proxy')
const consola = require('consola')
const app = express()

const host = '0.0.0.0'
const port = 3001
const proxyUrl = 'http://localhost:3000'

app.use(proxy(proxyUrl))

// $ brew install mkcert
// $ brew install nss // for firefox
// $ mkcert --install
// $ mkcert localhost 12.7.0.0.1 0.0.0.0 ::1 
const httpsOptions = {
  key: fs.readFileSync(`${__dirname}/localhost-key.pem`),
  cert: fs.readFileSync(`${__dirname}/localhost.pem`)
}

https.createServer(httpsOptions, app).listen(port, host)
consola.ready({
  message: `Server listening on https://${host}:${port}`,
  badge: true
})