|
1 |
| -import { EntryPoint, Inject, Injectable, Logger } from '@dandi/core' |
| 1 | +import { Server } from 'http' |
| 2 | + |
| 3 | +import { EntryPoint, Inject, Injectable, Injector, Logger } from '@dandi/core' |
| 4 | +import { HttpServer } from '@dandi/http-pipeline' |
2 | 5 | import { Route, RouteMapper, Routes } from '@dandi/mvc'
|
3 | 6 |
|
4 | 7 | import * as bodyParser from 'body-parser'
|
5 | 8 | import { Express } from 'express'
|
6 | 9 |
|
7 | 10 | import { ExpressInstance } from './express-instance'
|
8 |
| -import { ExpressMvcConfig } from './express-mvc-config' |
9 | 11 |
|
10 | 12 | @Injectable(EntryPoint)
|
11 |
| -export class ExpressMvcApplication implements EntryPoint { |
| 13 | +export class ExpressMvcApplication implements EntryPoint<Server> { |
12 | 14 | constructor(
|
13 | 15 | @Inject(ExpressInstance) private app: Express,
|
14 |
| - @Inject(ExpressMvcConfig) private config: ExpressMvcConfig, |
15 | 16 | @Inject(Routes) private routes: Route[],
|
16 | 17 | @Inject(RouteMapper) private routeMapper: RouteMapper,
|
| 18 | + @Inject(Injector) private injector: Injector, |
17 | 19 | @Inject(Logger) private logger: Logger,
|
18 | 20 | ) {}
|
19 | 21 |
|
20 |
| - public run(): void { |
| 22 | + public async run(): Promise<Server> { |
21 | 23 | this.app.use(bodyParser.raw({ type: '*/*' }))
|
22 | 24 |
|
23 | 25 | for (const route of this.routes) {
|
24 | 26 | this.routeMapper.mapRoute(route)
|
25 | 27 | }
|
26 | 28 |
|
27 |
| - this.logger.debug(`starting on ${this.config.host}:${this.config.port}`) |
28 |
| - this.app.listen(this.config.port, this.config.host) |
29 |
| - this.logger.info(`listening on http://${this.config.host}:${this.config.port}`) |
| 29 | + return await this.injector.inject(HttpServer) |
30 | 30 | }
|
31 | 31 | }
|
0 commit comments