Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import * as bodyParser from 'body-parser';
  2. import * as express from 'express';
  3.  
  4. // Creates and configures an ExpressJS web server.
  5. class App {
  6. // ref to Express instance
  7. express: express.Application;
  8.  
  9. // Run configuration methods on the Express instance.
  10. constructor() {
  11. // test
  12. this.express = express();
  13. this.middleware();
  14. this.routes();
  15. }
  16.  
  17. // Configure Express middleware.
  18. private middleware(): void {
  19. this.express.use(bodyParser.json());
  20. this.express.use(bodyParser.urlencoded({ extended: false }));
  21. }
  22.  
  23. // Configure API endpoints.
  24. private routes(): void {
  25. /* This is just to get up and running, and to make sure what we've got is
  26. * working so far. This function will change when we start to add more
  27. * API endpoints */
  28. const router = express.Router();
  29. // placeholder route handler
  30. router.get('/', (req: express.Request, res: express.Response, next: {}) => {
  31. res.json({
  32. message: 'Hello World!'
  33. });
  34. });
  35. this.express.use('/', router);
  36. }
  37.  
  38. }
  39.  
  40. export default new App().express;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement