-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
51 lines (43 loc) · 1.27 KB
/
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
43
44
45
46
47
48
49
50
51
/* eslint-disable global-require,no-console */
import express from 'express';
import colors from 'colors/safe';
import bodyParser from 'body-parser';
import serverlessify from './serverlessify';
import AuthCache from './AuthCache';
export default function createServer() {
console.log(colors.gray('Serving:'));
const http = express();
const authCache = new AuthCache();
http.set('port', (process.env.PORT || 3000));
http.set('trust proxy', true);
http.use(bodyParser.json());
const sls = serverlessify({
http,
authCache,
authorizers: {
'auth0-authorizer:authorize': (event, context, cb) =>
sls.getFunction('auth0-authorizer', 'authorize')(event, context, cb),
},
});
// Base auth0 authorizer
sls(
require('../sls-auth0-authorizer/serverless.yml'),
{ handler: require('../sls-auth0-authorizer/handler.js') }
);
sls(
require('../sls-example-user/serverless.yml'),
{ handler: require('../sls-example-user/handler.js') }
);
const startServer = () => http.listen(http.get('port'), () => {
console.log(colors.green(`🌍 Http server running http://0.0.0.0:${http.get('port')}`));
if (process.send) {
process.send('online');
}
});
return {
http,
authCache,
sls,
startServer,
};
}