Skip to content

Commit 73bfc9e

Browse files
committed
adding ssl termination demo
1 parent 9edf412 commit 73bfc9e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

demos/ssl-termination.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
const gateway = require('./../index')
4+
const PORT = process.env.PORT || 4443
5+
const https = require('https')
6+
const pem = require('pem')
7+
8+
pem.createCertificate({
9+
days: 1,
10+
selfSigned: true
11+
}, (err, keys) => {
12+
if (err) console.error(err)
13+
14+
gateway({
15+
restana: {
16+
server: https.createServer({
17+
key: keys.serviceKey,
18+
cert: keys.certificate
19+
})
20+
},
21+
middlewares: [
22+
],
23+
24+
routes: [{
25+
prefix: '/api',
26+
target: 'http://localhost:3000'
27+
}]
28+
}).start(PORT).then(server => {
29+
console.log(`API Gateway listening on ${PORT} port!`)
30+
})
31+
32+
const api = require('restana')({})
33+
api.get('/ssl-protected', (req, res) => {
34+
res.send('SSL Terminated!')
35+
})
36+
37+
api.start(3000).then(() => console.log('API service listening on 3000 port!'))
38+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"mocha": "^8.4.0",
5757
"nyc": "^15.1.0",
5858
"opossum": "^6.1.0",
59+
"pem": "^1.14.4",
5960
"request-ip": "^2.1.3",
6061
"response-time": "^2.3.2",
6162
"supertest": "^6.1.3"

0 commit comments

Comments
 (0)