Created
February 13, 2018 01:50
-
-
Save josecolella/65c549fda013c8fb0db59ee59bd93650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from 'path'; | |
import * as express from 'express'; | |
import * as logger from 'morgan'; | |
import * as bodyParser from 'body-parser'; | |
const app = express(); | |
// 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('combined')); | |
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); | |
} | |
} | |
export default new App().express; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment