-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.hbs
More file actions
55 lines (50 loc) · 1.52 KB
/
server.hbs
File metadata and controls
55 lines (50 loc) · 1.52 KB
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 express, { NextFunction, Request, Response } from 'express';
{{#each components}}
import {{@key}} from '../interfaces/{{@key}}.ts';
{{/each}}
{{#if description}}
/**
{{description}}
*/
{{/if}}
const app = express();
{{#paths}}
{{#methods}}
{{#if requestBody.required}}
{{#if parameters}}
app.{{methodName}}('{{{../route}}}', (req: Request<{ {{#parameters}}{{name}}: {{getType type}},{{/parameters}} }, {}, {{#with requestBody.content.[application/json]}}{{{getType this.type}}}{{/with}}>, res: Response) => {
{{/if}}
{{/if}}
{{#if requestBody.required}}
{{#unless parameters}}
app.{{methodName}}('{{{../route}}}', (req: Request<{}, {}, {{#with requestBody.content.[application/json]}}{{{getType this.type}}}{{/with}}>, res: Response) => {
{{/unless}}
{{/if}}
{{#unless requestBody.required}}
{{#if parameters}}
app.{{methodName}}('{{{../route}}}', (req: Request<{ {{#parameters}}{{name}}: {{getType type}},{{/parameters}} }>, res: Response) => {
{{/if}}
{{/unless}}
{{#unless requestBody.required}}
{{#unless parameters}}
app.{{methodName}}('{{{../route}}}', (req: Request, res: Response) => {
{{/unless}}
{{/unless}}
{{#if requestBody.required}}
if (
req.body === undefined
) {
res.sendStatus(400);
return;
}
{{/if}}
throw new Error('Method {{methodName}} for {{{../route}}} not implemented')
});
{{/methods}}
{{/paths}}
app.use((req: Request, res: Response, next: NextFunction) => {
res.sendStatus(404)
})
app.listen(3000, () => {
console.log('Server listening on port 3000...');
});