|
1 | 1 | import * as path from 'path';
|
2 |
| -import { Container } from 'typedi'; |
3 |
| -import { useContainer as ormUseContainer } from 'typeorm'; |
4 |
| -import { useContainer as routingUseContainer, createExpressServer } from 'routing-controllers'; |
| 2 | +import { createExpressServer } from 'routing-controllers'; |
5 | 3 | import { MicroframeworkSettings, MicroframeworkLoader } from 'microframework';
|
6 | 4 | import { env } from '../core/env';
|
7 | 5 | import { authorizationChecker } from '../auth/authorizationChecker';
|
8 | 6 | import { currentUserChecker } from '../auth/currentUserChecker';
|
9 | 7 |
|
10 | 8 |
|
11 | 9 | export const expressLoader: MicroframeworkLoader = (settings: MicroframeworkSettings | undefined) => {
|
| 10 | + if (settings) { |
| 11 | + const connection = settings.getData('connection'); |
12 | 12 |
|
13 |
| - /** |
14 |
| - * Setup routing-controllers to use typedi container. |
15 |
| - */ |
16 |
| - routingUseContainer(Container); |
17 |
| - ormUseContainer(Container); |
18 |
| - |
19 |
| - /** |
20 |
| - * We create a new express server instance. |
21 |
| - * We could have also use useExpressServer here to attach controllers to an existing express instance. |
22 |
| - */ |
23 |
| - const expressApp = createExpressServer({ |
24 |
| - cors: true, |
25 |
| - routePrefix: env.app.routePrefix, |
26 | 13 | /**
|
27 |
| - * We can add options about how routing-controllers should configure itself. |
28 |
| - * Here we specify what controllers should be registered in our express server. |
| 14 | + * We create a new express server instance. |
| 15 | + * We could have also use useExpressServer here to attach controllers to an existing express instance. |
29 | 16 | */
|
30 |
| - controllers: [path.join(__dirname, '..', 'api/controllers/*{.js,.ts}')], |
31 |
| - middlewares: [path.join(__dirname, '..', 'api/middlewares/*{.js,.ts}')], |
32 |
| - interceptors: [path.join(__dirname, '..', 'api/interceptors/*{.js,.ts}')], |
| 17 | + const expressApp = createExpressServer({ |
| 18 | + cors: true, |
| 19 | + routePrefix: env.app.routePrefix, |
| 20 | + /** |
| 21 | + * TODO: We can add options about how routing-controllers should configure itself. |
| 22 | + * Here we specify what controllers should be registered in our express server. |
| 23 | + */ |
| 24 | + controllers: [path.join(__dirname, '..', 'api/controllers/*{.js,.ts}')], |
| 25 | + middlewares: [path.join(__dirname, '..', 'api/middlewares/*{.js,.ts}')], |
| 26 | + interceptors: [path.join(__dirname, '..', 'api/interceptors/*{.js,.ts}')], |
33 | 27 |
|
34 |
| - /** |
35 |
| - * Authorization features |
36 |
| - */ |
37 |
| - authorizationChecker, |
38 |
| - currentUserChecker |
39 |
| - }); |
| 28 | + /** |
| 29 | + * Authorization features |
| 30 | + */ |
| 31 | + authorizationChecker: authorizationChecker(connection), |
| 32 | + currentUserChecker: currentUserChecker(connection) |
| 33 | + }); |
40 | 34 |
|
41 |
| - // Run application to listen on given port |
42 |
| - expressApp.listen(env.app.port); |
| 35 | + // Run application to listen on given port |
| 36 | + expressApp.listen(env.app.port); |
43 | 37 |
|
44 |
| - // Here we can set the data for other loaders |
45 |
| - if (settings) { |
| 38 | + // Here we can set the data for other loaders |
46 | 39 | settings.setData('express_app', expressApp);
|
47 | 40 | }
|
48 | 41 | };
|
0 commit comments