-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathApp.ts
46 lines (38 loc) · 1.2 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
39
40
41
42
43
44
45
46
import * as path from 'path';
import * as express from 'express';
import * as logger from 'morgan';
import * as bodyParser from 'body-parser';
import HeroRouter from './routes/HeroRouter';
// Creates and configures an ExpressJS web server.
class App {
// ref to Express instance
public express: express.Application;
//Run configuration methods on the Express instance.
constructor() {
this.express = express();
this.middleware();
this.routes();
}
// Configure Express middleware.
private middleware(): void {
this.express.use(logger('dev'));
this.express.use(bodyParser.json());
this.express.use(bodyParser.urlencoded({ extended: false }));
}
// Configure API endpoints.
private routes(): void {
/* This is just to get up and running, and to make sure what we've got is
* working so far. This function will change when we start to add more
* API endpoints */
let router = express.Router();
// placeholder route handler
router.get('/', (req, res, next) => {
res.json({
message: 'Hello World!'
});
});
this.express.use('/', router);
this.express.use('/api/v1/heroes', HeroRouter);
}
}
export default new App().express;