Skip to content

Instantly share code, notes, and snippets.

@josecolella
Created February 13, 2018 01:50
Show Gist options
  • Save josecolella/65c549fda013c8fb0db59ee59bd93650 to your computer and use it in GitHub Desktop.
Save josecolella/65c549fda013c8fb0db59ee59bd93650 to your computer and use it in GitHub Desktop.
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