index.js 905 B

1234567891011121314151617181920212223242526272829303132
  1. const express = require('express');
  2. const chalk = require('chalk');
  3. const expressLayouts = require('express-ejs-layouts')
  4. module.exports = function() {
  5. return {
  6. name: '@mws/server',
  7. type: 'server',
  8. auto_load: false,
  9. port: 5555,
  10. initialize: function(system) {
  11. this.system = system;
  12. },
  13. install: function(){
  14. this.app = express();
  15. this.app.set('view engine', 'ejs');
  16. this.app.use(expressLayouts);
  17. this.viewPaths = [];
  18. },
  19. setup: function(){
  20. },
  21. start: function(){
  22. this.app.set('views', this.viewPaths);
  23. this.app.listen(this.port, () => {
  24. let url = chalk.bold.cyan('http://localhost:' + this.port + '/');
  25. this.system.log(`${this.name} listening on port ${url}`);
  26. })
  27. }
  28. };
  29. }