-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
33 lines (27 loc) · 946 Bytes
/
app.ts
File metadata and controls
33 lines (27 loc) · 946 Bytes
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
import { Application } from 'express';
import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as mongoose from "mongoose";
import { FoodRoutes } from './routes/food';
class App {
public app: Application;
public foodRoutes: FoodRoutes = new FoodRoutes();
public mongoUrl: string = `mongodb://localhost/food_api`;
constructor() {
this.app = express();
this.config();
this.foodRoutes.routes(this.app);
this.setup();
}
private config(): void {
// support application/json type post data
this.app.use(bodyParser.json());
//support application/x-www-form-urlencoded post data
this.app.use(bodyParser.urlencoded({ extended: false }));
}
private setup(): void {
(mongoose as any).Promise = global.Promise;
mongoose.connect(this.mongoUrl, { useNewUrlParser: true });
}
}
export default new App().app;