-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlambda-wrapper.js
37 lines (33 loc) · 1.04 KB
/
lambda-wrapper.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
'use strict';
const {ExpressServer} = require('./server');
const serverless = require('serverless-http');
let app;
async function main(options) {
const server = new ExpressServer(options);
app = serverless(server.app);
await server.boot();
await server.start();
console.log('Server is running at http://127.0.0.1:3000');
}
exports.handler = async function handler(request, ...context) {
if (app === undefined) {
// Run the application
const config = {
rest: {
port: +(process.env.PORT ? process.env.PORT : 3000),
host: process.env.HOST ? process.env.HOST : 'localhost',
openApiSpec: {
// useful when used with OpenAPI-to-GraphQL to locate your application
setServersFromRequest: true,
},
// Use the LB4 application as a route. It should not be listening.
listenOnStart: false,
},
};
await main(config).catch(err => {
console.error('Cannot start the application.', err);
process.exit(1);
});
}
return app(request, ...context);
};