-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlambda.ts
41 lines (30 loc) · 1.01 KB
/
lambda.ts
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
import 'reflect-metadata'
import { Ignitor } from '@adonisjs/core/build/standalone'
import Serverlessize from '@satheler/s12r'
process.on('unhandledRejection', (reason) => {
console.error(reason)
})
process.on('uncaughtException', (reason) => {
console.error(reason)
})
let server: Function
async function bootstrapServer() {
const ignitor = new Ignitor(__dirname)
const httpServer = ignitor.httpServer()
await httpServer.application.setup()
await httpServer.application.registerProviders()
await httpServer.application.bootProviders()
await httpServer.application.requirePreloads()
const serverCore = httpServer.application.container.use('Adonis/Core/Server')
serverCore.errorHandler('App/Exceptions/Handler')
serverCore.optimize()
const server = serverCore.handle.bind(serverCore)
return server
}
export const handle = async (...args: any[]) => {
if (!server) {
server = await bootstrapServer()
}
const { request, response } = Serverlessize(args)
return server(request, response)
}