server.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * NodeJS-MVC 1.0
  3. * @Author HonorLee (deve@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. global.serverUID = (Math.ceil(Math.random()*61439+4096)).toString(16).toUpperCase();
  14. require('./config.js');
  15. require('./system/core.js');
  16. try{
  17. require('http').createServer(serverHandler).listen(Config.Server.Port);
  18. LOGGER.info('Child Server ['+serverUID+'] start at port [' + Config.Server.Port + '] | ' + Moment().format('YYYY/MM/DD hh:mm:ss', new Date()));
  19. }catch(e){
  20. LOGGER.error('Child Server ['+serverUID+'] failed start at port [' + Config.Server.Port + '] | ' + Moment().format('YYYY/MM/DD hh:mm:ss', new Date()));
  21. }
  22. function serverHandler(req,res){
  23. if(req.method.toLowerCase()=='post'){
  24. let form = new Formidable.IncomingForm();
  25. form.parse(req, function(err, fields, files) {
  26. req._POST = fields;
  27. req._UPLOAD = files;
  28. new ROUTER(req,res);
  29. });
  30. }else{
  31. new ROUTER(req,res);
  32. }
  33. }