{"id":285736,"date":"2017-04-30T13:30:32","date_gmt":"2017-04-30T09:30:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285736"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285736","title":{"rendered":"Nodejs MVC framework \u0438\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434"},"content":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440! \u041f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0438\u043a\u043e\u0433\u043e \u043d\u0435 \u0443\u0434\u0438\u0432\u043b\u044f\u0435\u0442 expressjs \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043d\u0430 node.js, \u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0442\u0430\u043c? \u042f \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044e \u043f\u0440\u043e \u0442\u043e, \u0447\u0442\u043e expressjs \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e, \u043d\u0435\u0442, \u043e\u043d \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f, \u0430 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u0432 expressjs \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435? \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043a\u0440\u043e\u043c\u0435 webserver \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u0430\u0440\u0430\u043c\u0438 \u2014 \u044d\u0442\u043e \u043c\u0435\u043b\u043e\u0447\u044c, \u0434\u0430 \u0438 middleware \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u0443\u0447\u0438 callback hell.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u043e\u043a\u0443 \u043f\u043e node.js \u0438 \u043c\u0435\u043b\u044c\u043a\u043e\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u044f\u0434\u0440\u0435, \u2014 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043b\u044f \u0441\u0435\u0431\u044f. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043f\u0440\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u0421\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0444\u0438\u043d\u0442\u044b \u0431\u044b\u043b\u0438 \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0441 php-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432.<\/p>\n<p>  \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0432\u0441\u0435 \u0436\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435:<\/p>\n<p>  async, hashids, mime-types, sequelize, validator, pug<\/p>\n<p>  1) \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\"> \u2014 dashboard \u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430<br \/>   \u2014 bin \u0444\u0430\u0439\u043b\u044b \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<br \/>   \u2014 config \u043a\u043e\u043d\u0444\u0438\u0433\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<br \/>   \u2014 migrations \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438<br \/>   \u2014 modules \u043c\u043e\u0434\u0443\u043b\u0438<br \/>   \u2014 views \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 view  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\"> \u2014 base \u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b<br \/>   \u2014 behaviors \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 \u0431\u0438\u0445\u0435\u0432\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432 90% \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432<br \/>   \u2014 console \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435<br \/>   \u2014 helpers \u043f\u0430\u043f\u043a\u0430 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0445\u0435\u043b\u043f\u0435\u0440\u0430\u043c\u0438<br \/>   \u2014 modules \u043c\u043e\u0434\u0443\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0432 90% \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 (\u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u0440\u0435\u043d\u0434\u0435\u0440 \u0441\u0442\u0430\u0442\u0438\u043a\u0438) <br \/>   \u2014 web \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f  <\/div>\n<\/div>\n<p>  2) \u041a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c web \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b bin\/server.js<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0424\u0430\u0439\u043b bin\/server.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import Application from &quot;dok-js\/dist\/web\/Application&quot;; import path from &quot;path&quot;;  const app = new Application({   basePath: path.join(__dirname, &quot;..&quot;),   id: &quot;server&quot; }); app.run();  export default app; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u043d\u0433 \u0438\u0437 .\/config\/server.js<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">.\/config\/server.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import path from &quot;path&quot;; export default function () {   return {     default: {       basePath: path.join(__dirname, &quot;..&quot;),       services: {         Database: {           options: {             instances: {               db: {                 database: &quot;example&quot;,                 username: &quot;example&quot;,                 password: &quot;example&quot;,                 params: {                   host: &quot;localhost&quot;,                   dialect: &quot;postgres&quot;                 }               }             }           }         },         Server: {           options: {             port: 1987           }         },         Router: {           options: {             routes: {               &quot;\/&quot;: {                 module: &quot;dashboard&quot;,                 controller: &quot;index&quot;,                 action: &quot;index&quot;               },               &quot;\/login&quot;: {                 module: &quot;identity&quot;,                 controller: &quot;identity&quot;,                 action: &quot;index&quot;               },               &quot;\/logout&quot;: {                 module: &quot;identity&quot;,                 controller: &quot;identity&quot;,                 action: &quot;logout&quot;               },               &quot;GET \/assets\/&lt;filePath:.*&gt;&quot;: {                 module: &quot;static&quot;,                 controller: &quot;static&quot;,                 action: &quot;index&quot;,                 params: {                   viewPath: path.join(__dirname, &quot;..&quot;, &quot;views&quot;, &quot;assets&quot;)                 }               },               &quot;\/&lt;module:\\w+&gt;\/&lt;controller:\\w+&gt;\/&lt;action:\\w+&gt;&quot;: {}             }           }         }       },       modules: {         identity: {           path: path.join(__dirname, &quot;..&quot;, &quot;modules&quot;, &quot;identity&quot;, &quot;IdentityModule&quot;)         },         dashboard: {           path: path.join(__dirname, &quot;..&quot;, &quot;modules&quot;, &quot;dashboard&quot;, &quot;DashboardModule&quot;)         }       }     }   }; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u043e\u0442 \u043c\u044b \u0438 \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043d\u0435 \u043d\u0435 \u0434\u0430\u043b \u044e\u0437\u0430\u0442\u044c \u0440\u043e\u0443\u0442\u044b \u043e\u0442 expressjs. \u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u043e\u0443\u0442\u043e\u0432 \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u0438\u0439 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0442\u043e\u043d\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u0443\u0442 \u044f \u0431\u0440\u0430\u043b \u0438\u0434\u0435\u0438 \u0441 yii2.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u044c \u043d\u043e\u043c\u0435\u0440 \u0434\u0432\u0430: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0438 \u044d\u043a\u0448\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 expressjs \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e nodejs-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432. \u042d\u0442\u043e \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 request \u0438 response \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0441 \u043d\u0438\u043c\u0438 \u0432\u0441\u0435 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u0442.\u0435. \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u043e\u0442\u043a\u043d\u0443\u0442\u044c \u043b\u043e\u0433\u0433\u0435\u0440, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0440\u0435\u0441\u043f\u043e\u043d\u0437\u043e\u0432, \u0431\u0443\u0434\u044c \u0434\u043e\u0431\u0440 \u043f\u0440\u043e\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438 \u043d\u0435 \u0434\u0430\u0439 \u0431\u043e\u0433 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 next(request, response), \u044d\u0442\u043e \u044f \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u043d\u0430\u0435\u0448\u044c \u0432 \u043a\u0430\u043a\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0432\u043e\u0439 \u044d\u043a\u0448\u0435\u043d \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0441\u0432\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">base\/Request.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">async run(ctx) {     this.constructor.parse(ctx);     try {       ctx.route = App().getService(&quot;Router&quot;).getRoute(ctx.method, ctx.url);     } catch (e) {       return App().getService(&quot;ErrorHandler&quot;).handle(404, e.message);     }      try {       return App().getModule(ctx.route.moduleName).runAction(ctx);     } catch (e) {       return App().getService(&quot;ErrorHandler&quot;).handle(500, e.message);     }   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">base\/Module.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">async runAction(ctx) {     const {controllerName, actionName} = ctx.route;     const controller = this.createController(controllerName);     if (!controller[actionName]) {       throw new Error(`Action &quot;${actionName}&quot; in controller &quot;${controllerName}&quot; not found`);     }      const result = await this.runBehaviors(ctx, controller);     if (result) {       return result;     }     return controller[actionName](ctx);   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422.\u0435. \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u0440\u0440\u043e\u0432.<\/p>\n<p>  \u041d\u0443 \u0438 \u0441\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">modules\/dashboard\/controllers\/IndexController.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import Controller from &quot;dok-js\/dist\/web\/Controller&quot;; import AccessControl from &quot;dok-js\/dist\/behaviors\/AccessControl&quot;; export default class IndexController extends Controller {    getBehaviors() {     return [{       behavior: AccessControl,       options: [{         actions: [&quot;index&quot;],         roles: [&quot;user&quot;]       }]     }];   }    indexAction() {     return this.render(&quot;index&quot;);   } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">modules\/identity\/controllers\/IdentityController.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import Controller from &quot;dok-js\/dist\/web\/Controller&quot;; import SignInForm from &quot;..\/data-models\/SignInForm&quot;;  export default class IdentityController extends Controller {    async indexAction(ctx) {     const data = {};     data.meta = {       title: &quot;\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f&quot;     };      if (ctx.method === &quot;POST&quot;) {       const signInForm = new SignInForm();       signInForm.load(ctx.body);       const $user = await signInForm.login(ctx);       if ($user) {         return this.redirectTo(&quot;\/&quot;, 301);       }       data.signInForm = signInForm;     }      return this.render(&quot;sign-in&quot;, data);   }    logoutAction(ctx) {     ctx.session.clearSession();     return this.redirectTo(&quot;\/&quot;, 302);   }  } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f 1 \u0440\u0430\u0437 \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0435\u0448.<\/p>\n<p>  \u0421\u0430\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0435\u0449\u0435 \u0441\u044b\u0440\u043e\u0432\u0430\u0442, \u043d\u043e \u043d\u0430 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435:<\/p>\n<p>  <a href=\"https:\/\/github.com\/kalyuk\/dok-js\">github.com\/kalyuk\/dok-js<\/a><\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043c \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u0440\u043e\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <a href=\"https:\/\/github.com\/kalyuk\/dok-js-example\">github.com\/kalyuk\/dok-js-example<\/a><br \/> \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\/327638\/\"> https:\/\/habrahabr.ru\/post\/327638\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440! \u041f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0438\u043a\u043e\u0433\u043e \u043d\u0435 \u0443\u0434\u0438\u0432\u043b\u044f\u0435\u0442 expressjs \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043d\u0430 node.js, \u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0442\u0430\u043c? \u042f \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044e \u043f\u0440\u043e \u0442\u043e, \u0447\u0442\u043e expressjs \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e, \u043d\u0435\u0442, \u043e\u043d \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f, \u0430 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u0432 expressjs \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435? \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043a\u0440\u043e\u043c\u0435 webserver \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u0430\u0440\u0430\u043c\u0438 \u2014 \u044d\u0442\u043e \u043c\u0435\u043b\u043e\u0447\u044c, \u0434\u0430 \u0438 middleware \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u0443\u0447\u0438 callback hell.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u043e\u043a\u0443 \u043f\u043e node.js \u0438 \u043c\u0435\u043b\u044c\u043a\u043e\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u044f\u0434\u0440\u0435, \u2014 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043b\u044f \u0441\u0435\u0431\u044f. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043f\u0440\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434.   <\/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-285736","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285736","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=285736"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285736\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}