* Start the HTTP server by wiring up the application * * @param serverCallback - Optional callback to create custom HTTP server instance
(
serverCallback?: (
handler: (req: IncomingMessage, res: ServerResponse) => any
) => NodeHttpsServer | NodeHttpServer
)
| 150 | * @param serverCallback - Optional callback to create custom HTTP server instance |
| 151 | */ |
| 152 | async start( |
| 153 | serverCallback?: ( |
| 154 | handler: (req: IncomingMessage, res: ServerResponse) => any |
| 155 | ) => NodeHttpsServer | NodeHttpServer |
| 156 | ) { |
| 157 | const startTime = process.hrtime() |
| 158 | |
| 159 | /** |
| 160 | * Method to create the HTTP server |
| 161 | */ |
| 162 | const createHTTPServer = serverCallback || createServer |
| 163 | const app = this.#ignitor.createApp('web') |
| 164 | |
| 165 | await app.init() |
| 166 | await app.boot() |
| 167 | await app.start(async () => { |
| 168 | /** |
| 169 | * Resolve and boot the AdonisJS HTTP server |
| 170 | */ |
| 171 | const server = await app.container.make('server') |
| 172 | await server.boot() |
| 173 | |
| 174 | /** |
| 175 | * Create Node.js HTTP server instance and share it with the |
| 176 | * AdonisJS HTTP server |
| 177 | */ |
| 178 | const httpServer = createHTTPServer(server.handle.bind(server)) |
| 179 | server.setNodeServer(httpServer) |
| 180 | |
| 181 | const logger = await app.container.make('logger') |
| 182 | const emitter = await app.container.make('emitter') |
| 183 | |
| 184 | /** |
| 185 | * Start the server by listening on a port of host |
| 186 | */ |
| 187 | const payload = await this.#listen(httpServer) |
| 188 | |
| 189 | /** |
| 190 | * Notify |
| 191 | */ |
| 192 | this.#notifyServerHasStarted(app, logger, emitter, { |
| 193 | ...payload, |
| 194 | duration: process.hrtime(startTime), |
| 195 | }) |
| 196 | |
| 197 | /** |
| 198 | * Monitor app and the server (after the server is listening) |
| 199 | */ |
| 200 | this.#monitorAppAndServer(httpServer, app, logger) |
| 201 | }) |
| 202 | } |
| 203 | } |
no test coverage detected