Skip to content

Commit

Permalink
Support for https
Browse files Browse the repository at this point in the history
  • Loading branch information
f213 committed Nov 18, 2021
1 parent 335d611 commit f20e91f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM node:16-alpine

RUN apk update && apk --no-cache add dumb-init
RUN apk update && apk --no-cache add dumb-init openssl

RUN openssl req -x509 -nodes -days 3650 -subj "/C=CA/ST=QC/O=Localhost Administration, Inc./CN=localhost" -addext \
"subjectAltName=DNS:localhost" -newkey rsa:2048 -keyout /etc/ssl/private/express-selfsigned.key -out /etc/ssl/certs/express-selfsigned.crt;

ADD . /srv
WORKDIR /srv
RUN npm ci

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD node /srv/index.js
CMD node /srv/index.js
29 changes: 22 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
var express = require('express');
var proxy = require('http-proxy-middleware');
var fs = require('fs');
var https = require('https');
var createProxyMiddleware = require('http-proxy-middleware');
var morgan = require('morgan');

var app = express();

app.use(morgan('combined'));
app.use(
'/',
proxy({

app.use('/', createProxyMiddleware({
target: process.env.TARGET,
changeOrigin: true,
followRedirects: true,
}),
);
app.listen(3000);
})
)

const port = process.env.PORT || 3000;

if (process.env.SELF_SIGNED_TLS) {
var key = fs.readFileSync( '/etc/ssl/private/express-selfsigned.key' );
var cert = fs.readFileSync( '/etc/ssl/certs/express-selfsigned.crt' );

https.createServer({key, cert}, app).listen(port);
console.log(`[HTTPS] Listening on 0.0.0.0:${port}...`);
console.log('Google chrome users, to allow https on localhost, go to chrome://flags/#allow-insecure-localhost');
} else {
app.listen(port);
console.log(`Listening on 0.0.0.0:${port}...`);
}

0 comments on commit f20e91f

Please sign in to comment.