{"id":280310,"date":"2016-11-01T18:35:03","date_gmt":"2016-11-01T15:35:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280310"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280310","title":{"rendered":"\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 MVC \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0442\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0430 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435"},"content":{"rendered":"<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430! \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043c\u0438\u0440 JS, \u043a\u043e\u0438\u043c \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0438 \u044f. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Node.js \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0410 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e url, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"http:\/\/127.0.0.1\/habr\">http:\/\/127.0.0.1\/habr<\/a> \u0438 <a href=\"http:\/\/127.0.0.1\/habrahabr\">http:\/\/127.0.0.1\/habrahabr<\/a>. \u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443. <\/p>\n<p>  <b>\u0426\u0435\u043b\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u2013 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432.<\/b><br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u043f\u043e\u0434\u043d\u044f\u0442\u044c <a href=\"https:\/\/learn.javascript.ru\/ajax-nodejs\">\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Node.js<\/a><\/p>\n<pre><code>var http = require('http'); var file = new static.Server('.'); http.createServer(function(req, res) {   file.serve(req, res); }).listen(80);<\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043a\u043e\u0434, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/nodejs.org\/api\/cluster.html\">cluster<\/a>:<\/p>\n<pre><code class=\"javascript\">const cluster = require('cluster'); const http = require('http'); const domain = require('domain');  const numCPUs = require('os').cpus().length;  if (cluster.isMaster) {   for (var i = 0; i &lt; numCPUs; i++) {     cluster.fork();   }   cluster.on('exit', function(worker, code, signal){     console.log('worker ' + worker.process.pid +' died');     cluster.fork();   });   cluster.on('online', function(worker) {       console.log('Worker ' + worker.process.pid + ' is online');   }); } else {   http.createServer(function(req, res){ \t    \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u043c\u0435\u043d \t    var d = domain.create(); \t    \/\/ \u0412\u0435\u0448\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0435\u0442 500\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \t    d.on('error', function(err) { \t        res.statusCode = 500; \t        res.setHeader('content-type', 'text\/plain'); \t        res.end('\u041e\u0448\u0438\u0431\u043a\u0430!\\n'+ err.stack); \t    }); \t    \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \t    d.add(req); \t    d.add(res); \t    \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043c\u0435\u043d\u0430 \t    d.run(function () { \t    \tvar route_json = require('.\/application\/route.json'); \t    \tif( route_json[req.url] !== undefined){\/\/\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u043b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \t    \t\tconsole.log(route_json[req.url].controller); \t    \t}else{ \t    \t\t url = urlapi.parse(decodeURI(req.url), true);\/\/\u043f\u0430\u0440\u0441\u0438\u043c url \t    \t\t url_arr = url.pathname.slice(1).split('\/');\/\/\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c url \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \t    \t} \t    \tres.end('hello world'); \t    }); }).listen(3031).on('connection', function(socket) { socket.setNoDelay(); \/\/ \u041e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041d\u0430\u0433\u043b\u0430. });       } <\/code><\/pre>\n<p>  \u0421 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 url. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0443 MVC, \u0442\u043e \u0437\u0430 \u044d\u0442\u0430\u043b\u043e\u043d \u0432\u043e\u0437\u044c\u043c\u0435\u043c codeigniter. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/medicalrink.com\/habr1.png\" alt=\"image\"\/><\/p>\n<p>  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b:<\/p>\n<ul>\n<li>app.js \u2014 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/li>\n<li>core \u2014 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0444\u0430\u043b\u044b \u044f\u0434\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0442.\u043f.<\/li>\n<li>aplication \u2014 \u043f\u0430\u043f\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\n<ul>\n<li>controller- \u043f\u0430\u043f\u043a\u0430 c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438<\/li>\n<li>model- \u043f\u0430\u043f\u043a\u0430 c \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438<\/li>\n<li>model- \u043f\u0430\u043f\u043a\u0430 c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438<\/li>\n<li>route.json \u2014 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0440\u043e\u0443\u0442\u0438\u043d\u0433<\/li>\n<\/ul>\n<p>  <\/li>\n<\/ul>\n<p>  \u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<ul>\n<li>require \u2014 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/li>\n<li>eval \u2014 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0439 \u0447\u0435\u043c vm, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u044d\u0442\u043e \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/li>\n<li>vm \u2014 \u044d\u0442\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435. \u041f\u043b\u044e\u0441\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0442\u0435\u0447\u0435\u043a \u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0440\u0430\u0431\u043e\u0442\u043e\u0439, \u043c\u043e\u0436\u043d\u043e \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442\u044c \u043d\u0435 \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435, \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u0441\u044f.<\/li>\n<\/ul>\n<p>  \u0418\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e vm \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 \u043d\u043e\u0432\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043b\u0438\u0431\u043e \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c. \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0432 \u043d\u043e\u0432\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">const cluster = require('cluster'); const http = require('http'); const domain = require('domain');  const numCPUs = require('os').cpus().length;  if (cluster.isMaster) {   for (var i = 0; i &lt; numCPUs; i++) {     cluster.fork();   }   cluster.on('exit', function(worker, code, signal){     console.log('worker ' + worker.process.pid +' died');     cluster.fork();   });   cluster.on('online', function(worker) {       console.log('Worker ' + worker.process.pid + ' is online');   }); } else {   http.createServer(function(req, res){ \t    \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u043c\u0435\u043d \t    var d = domain.create(); \t    \/\/ \u0412\u0435\u0448\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0435\u0442 500\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \t    d.on('error', function(err) { \t        res.statusCode = 500; \t        res.setHeader('content-type', 'text\/plain'); \t        res.end('\u041e\u0448\u0438\u0431\u043a\u0430!\\n'+ err.stack); \t    }); \t    \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \t    d.add(req); \t    d.add(res); \t    \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043c\u0435\u043d\u0430 \t    d.run(function () { \t    \tvar route_json = require('.\/application\/route.json'); \t    \tvar fs = require('fs');\/\/\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \t    \tif( route_json[req.url] !== undefined){\/\/\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u043b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \t    \t\tvar path = '.\/application\/controller\/'+route_json[req.url].controller+'.js'; \t    \t}else{ \t    \t\t var urlapi = require('url');\/\/\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 url \t    \t\t var url = urlapi.parse(decodeURI(req.url), true);\/\/\u043f\u0430\u0440\u0441\u0438\u043c url \t    \t\t var url_arr = url.pathname.slice(1).split('\/');\/\/\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c url \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \t    \t\t var path = '.\/application\/controller\/'+url_arr[0]+'.js'; \t    \t} \t   \t\t \/\/\u0427\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u0437 \u043f\u0430\u043f\u043a\u0438 \t   \t\t fs.readFile(path, 'utf8',  \t   \t\t function(err, code) { \t   \t\t\tvar vm = require('vm'); \t     \t\t  \tvar timestart =  parseInt(new Date().getTime()); \t     \t\t  \tvar pid = cluster.worker.process.pid; \t     \t\t        var context = { \t\t\t\t\t\t\t\/\/ -- \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 \t     \t\t\t\t                pid:pid, \t\t\t\t\t\t\tres:res, \t\t\t\t\t\t\treq:req, \t\t\t\t\t\t\ttimestart:timestart, \t\t\t\t\t\t        require: require, \t\t\t\t\t\t        console: console \t\t\t\t\t\t}; \t\t      \t\tvar vmContext =  vm.createContext(context); \t\t\t\t\tvar script =  vm.Script(code); \t\t\t\t\tscript.runInNewContext(vmContext); \t   \t\t }); \t    }); }).listen(3031).on('connection', function(socket) { socket.setNoDelay(); \/\/ \u041e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041d\u0430\u0433\u043b\u0430. });       } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Headers', 'origin, content-type, accept'); res.setHeader(&quot;Cache-Control&quot;, &quot;no-cache, must-revalidate&quot;); res.writeHead(200, {&quot;Content-Type&quot;: &quot;text\/plain&quot;}); res.write('CONTROLLER RUN'); res.end(); <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u0440\u043a\u0430\u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435). <\/p>\n<p>  \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 cluster \u0438 vm, \u0434\u043e\u043c\u0435\u043d\u044b \u0432 Node.js.<\/p>\n<p>  \u0421\u0441\u044b\u043b\u043a\u0438:<\/p>\n<ol>\n<li><a href=\"https:\/\/learn.javascript.ru\/ajax-nodejs\">learn.javascript.ru\/ajax-nodejs<\/a><\/li>\n<li><a href=\"https:\/\/nodejs.org\/api\/cluster.html\">nodejs.org\/api\/cluster.html<\/a><\/li>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/Model-View-Controller\">ru.wikipedia.org\/wiki\/Model-View-Controller<\/a><\/li>\n<li><a href=\"http:\/\/code-igniter.ru\/user_guide\/libraries\/uri.html\">code-igniter.ru\/user_guide\/libraries\/uri.html<\/a><\/li>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/JSON\">ru.wikipedia.org\/wiki\/JSON<\/a><\/li>\n<li><a href=\"https:\/\/nodejs.org\/api\/domain.html\">nodejs.org\/api\/domain.html<\/a><\/li>\n<li><a href=\"https:\/\/nodejs.org\/api\/vm.html\">nodejs.org\/api\/vm.html<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pan-alexey\/nodeigniter\">https:\/\/github.com\/pan-alexey\/nodeigniter<\/a> \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430 github<\/li>\n<\/ol>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/314186\/\"> https:\/\/habrahabr.ru\/post\/314186\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430! \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043c\u0438\u0440 JS, \u043a\u043e\u0438\u043c \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0438 \u044f. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Node.js \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0410 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e url, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"http:\/\/127.0.0.1\/habr\">http:\/\/127.0.0.1\/habr<\/a> \u0438 <a href=\"http:\/\/127.0.0.1\/habrahabr\">http:\/\/127.0.0.1\/habrahabr<\/a>. \u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443. <\/p>\n<p>  <b>\u0426\u0435\u043b\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u2013 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432.<\/b>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-280310","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280310"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280310\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}