/
expressApplication.ts
55 lines (53 loc) · 1.77 KB
/
expressApplication.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {Type} from "@tsed/core";
import {Inject} from "@tsed/di";
import * as Express from "express";
declare global {
namespace Express {
interface Application {
use: (middleware: any) => Application;
}
}
}
/**
* `ExpressApplication` is an alias type to the [Express.Application](http://expressjs.com/fr/4x/api.html#app) interface. It use the util `registerFactory()` and let you to inject [Express.Application](http://expressjs.com/fr/4x/api.html#app) created by the Server.
*
* ```typescript
* import {ExpressApplication, Service, Inject} from "@tsed/common";
*
* @Service()
* export default class OtherService {
* constructor(@ExpressApplication expressApplication: Express.Application) {}
* }
* ```
*
* > Note: TypeScript transform and store `ExpressApplication` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
*
* @type {symbol}
*/
export type ExpressApplication = Express.Application;
/**
* Inject the express application instance.
*
* ::: tip
* Prefer @@PlatformApplication@@ usage if you want to be compliant with the new Platform abstraction.
* :::
*
* ```typescript
* import {ExpressApplication, Service, Inject} from "@tsed/common";
*
* @Service()
* export default class OtherService {
* constructor(@ExpressApplication expressApplication: Express.Application) {}
* }
* ```
*
* @param {Type<any>} target
* @param {string} targetKey
* @param {TypedPropertyDescriptor<Function> | number} descriptor
* @returns {any}
* @decorator
* @deprecated use PlatformApplication instead of
*/
export function ExpressApplication(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number) {
return Inject(ExpressApplication)(target, targetKey, descriptor);
}