-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.ts
38 lines (31 loc) · 1.1 KB
/
app.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
import * as express from "express";
import * as serverless from "serverless-http";
import * as aws from "aws-sdk";
import * as bodyParser from "body-parser";
import { PlannerRoutes } from "./src/routes/plannerRoutes";
class App {
private app: express.Application;
constructor() {
this.app = express();
this.app.use(bodyParser.json({ strict: false }));
}
start(): express.Application {
this.setCors(this.app);
this.setRoutes(this.app);
return this.app;
}
private setCors(app: express.Application): void {
app.use((req: express.Request, res: express.Response, next: express.NextFunction): void => {
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
}
private setRoutes(app: express.Application): void {
const plannerRoutes = new PlannerRoutes();
plannerRoutes.routes(this.app);
}
}
const app = new App().start();
export const handler = serverless(app);