-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
42 lines (32 loc) · 809 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict'
const express = require('express')
const jwksRsa = require('jwks-rsa')
const expressJwt = require('express-jwt')
const routes = require('./routes')
const config = require('./config')
const start = port => {
const app = express()
const checkJwt = expressJwt({
// Validate the audience and the issuer.
audience: config.auth0.audience,
issuer: config.auth0.issuer,
algorithms: ['RS256'],
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `${config.auth0.issuer}.well-known/jwks.json`
}),
})
app.use(checkJwt)
app.use('/api', routes)
const apiPort = port || 4000
return app.listen(apiPort)
}
const stop = async app => {
process.exit(0)
}
module.exports = {
start,
stop,
}