server.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * NodeJS-MVC 1.0
  3. * --------------------
  4. * HonorLee
  5. * http://honorlee.me
  6. * dev@honorlee.me
  7. */
  8. /*
  9. * Worker Process
  10. DO NOT CHANGE ANYTHING IN THIS FILE!
  11. */
  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 + '] | ' + DateFormat('yyyy/MM/dd hh:mm:ss', new Date()));
  19. }catch(e){
  20. LOGGER.error('Child Server ['+serverUID+'] failed start at port [' + Config.Server.Port + '] | ' + DateFormat('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. }