server.js 1012 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * NodeJS-MVC 1.0
  3. * @Author HonorLee (dev@honorlee.me)
  4. * @Version 1.0 (2018-05-04)
  5. * @License MIT
  6. */
  7. /*
  8. * Worker Process
  9. * DO NOT CHANGE ANYTHING IN THIS FILE!
  10. */
  11. 'use strict'
  12. global.ROOTPATH = __dirname;
  13. require('./config.js');
  14. require('./system/core.js');
  15. try{
  16. require('http').createServer(serverHandler).listen(Config.Server.Port);
  17. LOGGER.info('Child Server ['+serverUID+'] start at port [' + Config.Server.Port + '] | ' + Moment().format('YYYY/MM/DD hh:mm:ss', new Date()));
  18. }catch(e){
  19. LOGGER.error('Child Server ['+serverUID+'] failed start at port [' + Config.Server.Port + '] | ' + Moment().format('YYYY/MM/DD hh:mm:ss', new Date()));
  20. }
  21. function serverHandler(req,res){
  22. if(req.method.toLowerCase()=='post'){
  23. let form = new Formidable.IncomingForm();
  24. form.parse(req, function(err, fields, files) {
  25. req._POST = fields;
  26. req._UPLOAD = files;
  27. new ROUTER(req,res);
  28. });
  29. }else{
  30. new ROUTER(req,res);
  31. }
  32. }