server.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. let serverPort = Config.ServerPort;
  17. try{
  18. require('http').createServer(serverHandler).listen(serverPort);
  19. LOGGER.info('Child Server ['+serverUID+'] start at port [' + serverPort + '] | ' + DateFormat('yyyy/MM/dd hh:mm:ss', new Date()));
  20. }catch(e){
  21. LOGGER.error('Child Server ['+serverUID+'] failed start at port [' + serverPort + '] | ' + DateFormat('yyyy/MM/dd hh:mm:ss', new Date()));
  22. }
  23. function serverHandler(req,res){
  24. if(req.method.toLowerCase()=='post'){
  25. let form = new Formidable.IncomingForm();
  26. form.parse(req, function(err, fields, files) {
  27. req._POST = fields;
  28. req._UPLOAD = files;
  29. new ROUTER(req,res);
  30. });
  31. }else{
  32. new ROUTER(req,res);
  33. }
  34. }