-
Notifications
You must be signed in to change notification settings - Fork 124
/
slim.ts
36 lines (30 loc) · 847 Bytes
/
slim.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
import { App } from '@deepkit/app';
import { http, HttpKernel, HttpModule, HttpRequest, HttpResponse } from '@deepkit/http';
import { Server } from 'http';
class MyService {
helloWorld () {
return 'Hello World'
}
}
class MyController {
constructor(private myService: MyService) {
}
@http.GET()
hello(response: HttpResponse) {
response.end(this.myService.helloWorld());
}
}
const app = new App({
providers: [MyService, MyController],
controllers: [MyController],
imports: [new HttpModule]
});
const httpKernel = app.get(HttpKernel);
new Server(
{ IncomingMessage: HttpRequest, ServerResponse: HttpResponse as any, },
((req, res) => {
httpKernel.handleRequest(req as HttpRequest, res as HttpResponse);
})
).listen(8080, () => {
console.log('listen at 8080');
});