SSL connection?
Closed this issue · 1 comments
Capurim commented
Hello,
Is it possible to handle SSL/TLS connection and set our certificate and keys?
With https
library we can add credential as option like this:
const credentials = {
key: /* my key */,
cert: /* my certificate */
}
https.createServer(credentials, app).listen(443, () => {
console.log('Server started on port 443')
})
I don't see something like that in your doc.
Thank you.
Capu
jkyberneees commented
Hi @Capurim, fast-gateway uses restana
as default HTTP server. Therefore you can do:
'use strict'
const gateway = require('fast-gateway')
const PORT = process.env.PORT || 4443
const https = require('https')
const pem = require('pem')
pem.createCertificate({
days: 1,
selfSigned: true
}, (err, keys) => {
if (err) console.error(err)
gateway({
restana: {
server: https.createServer({
key: keys.serviceKey,
cert: keys.certificate
})
},
middlewares: [
],
routes: [{
prefix: '/api',
target: 'http://localhost:3000'
}]
}).start(PORT).then(server => {
console.log(`API Gateway listening on ${PORT} port!`)
})
const api = require('restana')({})
api.get('/ssl-protected', (req, res) => {
res.send('SSL Terminated!')
})
api.start(3000).then(() => console.log('API service listening on 3000 port!'))
})
Then: https://localhost:4443/api/ssl-protected
PS: This demo is now added to the repository.