Skip to content

Commit 632bd60

Browse files
committed
Added SSL listener
1 parent 69befc5 commit 632bd60

5 files changed

Lines changed: 88 additions & 7 deletions

File tree

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
FROM yolean/node@sha256:230b269710a1d09b9ebbdeeea0fc4e69ac1388ab71b0178452e817065f69c700
1+
FROM node:9.2-alpine
22

33
WORKDIR /app
44

5-
COPY package.json package-lock.json ./
5+
COPY . .
6+
67
RUN npm install --production
78

8-
COPY . .
9+
RUN apk --no-cache add openssl
10+
11+
RUN sh generate-cert.sh
12+
13+
EXPOSE 80 443
14+
915

1016
ENTRYPOINT ["node", "./index.js"]
1117
CMD []

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
`docker run -p 80:80 -e PORT=80 --rm -t solsson/http-echo`
1+
Docker image which echoes various HTTP request properties back to client, as well as in docker logs.
2+
3+
Sample output:
4+
5+
## Usage
6+
7+
docker run -p 80:80 --rm -t mendhak/http-echo
8+
9+
10+
## In Docker Compose
11+
12+
13+
14+
15+
## Building
16+
17+
docker build -t mendhak/http-echo .
18+
19+

generate-cert.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
# source : https://raw.githubusercontent.com/Daplie/nodejs-self-signed-certificate-example/master/make-root-ca-and-certificates.sh
3+
4+
set -e
5+
6+
# Create your very own Root Certificate Authority
7+
openssl genrsa \
8+
-out root-ca.key.pem \
9+
2048
10+
11+
# Self-sign your Root Certificate Authority
12+
# Since this is private, the details can be as bogus as you like
13+
openssl req \
14+
-x509 \
15+
-new \
16+
-nodes \
17+
-key root-ca.key.pem \
18+
-days 9999 \
19+
-out root-ca.crt.pem \
20+
-subj "/C=US/ST=Utah/L=Provo/O=ACME Signing Authority Inc/CN=example.com"
21+
22+
# Create a Device Certificate
23+
openssl genrsa \
24+
-out privkey.pem \
25+
2048
26+
27+
# Create a request from your Device, which your Root CA will sign
28+
openssl req -new \
29+
-key privkey.pem \
30+
-out device-csr.pem \
31+
-subj "/C=US/ST=Utah/L=Provo/O=ACME Tech Inc/CN=my.example.com"
32+
33+
# Sign the request from Device with your Root CA
34+
# -CAserial certs/ca/my-root-ca.srl
35+
openssl x509 \
36+
-req -in device-csr.pem \
37+
-CA root-ca.crt.pem \
38+
-CAkey root-ca.key.pem \
39+
-CAcreateserial \
40+
-out cert.pem \
41+
-days 9999
42+
43+
# Put things in their proper place
44+
cat cert.pem root-ca.crt.pem > fullchain.pem

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var express = require('express')
22
const morgan = require('morgan');
3+
var http = require('http')
4+
var https = require('https')
35
var app = express()
46
const os = require('os');
57
const jwt = require('jsonwebtoken');
@@ -49,7 +51,14 @@ app.all('*', (req, res) => {
4951
console.log(echo);
5052
});
5153

52-
const server = app.listen(process.env.PORT || 80);
54+
const sslOpts = {
55+
key: require('fs').readFileSync('privkey.pem'),
56+
cert: require('fs').readFileSync('fullchain.pem'),
57+
};
58+
59+
http.createServer(app).listen(80);
60+
https.createServer(sslOpts,app).listen(443);
61+
5362
let calledClose = false;
5463

5564
process.on('exit', function () {

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
2-
"name": "@solsson/http-echo",
2+
"name": "@mendhak/http-echo",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/mendhak/docker-http-echo"
6+
},
37
"version": "1.0.1",
48
"description": "JSON service for debugging a web setup",
59
"main": "index.js",
610
"scripts": {
711
"start": "node index.js",
812
"test": "echo \"Error: no test specified\" && exit 1"
913
},
10-
"author": "Ryan Muller <ryan@kennship.com>",
14+
"author": "Mendhak <gpslogger@mendhak.com>",
1115
"license": "BSD-3-Clause",
1216
"engines": {
1317
"node": ">=6.3.0"

0 commit comments

Comments
 (0)