{"id":200356,"date":"2013-11-01T13:18:02","date_gmt":"2013-11-01T09:18:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=200356"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=200356","title":{"rendered":"<span class=\"post_title\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 javascript (\u0447\u0430\u0441\u0442\u044c 2 \u2014 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435)<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c8c\/465\/1b0\/c8c4651b03cb9d0789cd33ed8b057440.png\" alt=\"image\" align=\"left\"\/>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0438 \u043e\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435 openshift.<br \/>  <a name=\"habracut\"><\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/200192\/\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 javascript (\u0447\u0430\u0441\u0442\u044c 1 \u2014 \u043a\u043b\u0438\u0435\u043d\u0442)<\/a><\/p>\n<p>  \u0421\u0435\u0440\u0432\u0435\u0440 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 nodejs \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c swagger-node-express. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e <a href=\"http:\/\/myconference.php.poltava.ua\/docs\/\">\u0430\u0432\u0442\u043e\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u0425\u043e\u0447\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f, \u0441\u043a\u043e\u0440\u0435\u0435, \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0446\u0438\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043e\u043f\u0443\u0449\u0435\u043d\u044b \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435.<\/p>\n<p>  \u0421\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0412 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0432\u0441\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f.<\/p>\n<pre><code class=\"javascript\">var express = require(&quot;express&quot;),  swagger = require(&quot;.\/swagger&quot;),  orm = require('.\/orm'),  auth = require('.\/auth'),  config = require('.\/config'),  static_files = require('.\/static');  var app = express();  app.use(express.bodyParser());  auth.init(app); orm.init(app); swagger(app); static_files(app);  app.listen(config.listen, config.ipaddr); <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438. \u0414\u043b\u044f \u0430\u0432\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f http \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0435\u0433\u043e \u0438\u043c\u044f \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445. \u0421\u0435\u0441\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 memcached, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 api_key -&gt; user_id. \u041a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"javascript\">var client = new memcache.Client(cfg.memcache.port, cfg.memcache.host); ... app.use(function(req, res, next){ \tclient.get( \t\treq.headers[cfg.header.toLowerCase()], \t\tfunction(error, result){ \t\t\tif(result){ \t\t\t\treq.user = result; \t\t\t} \t\t\tnext(); \t\t} \t);  \treq.memcache = client; }); <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f node-orm2. \u041e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0432 package.json \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0442 \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<br \/>  \u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<pre><code class=\"javascript\">app.use(orm.express(config.db, {     define: function (db, models) {          db.define(&quot;users&quot;,           {             id       : Number,             email    : String,             password : String,             twitter  : Number,             facebook : Number,             google   : Number,             linkedin : String         },         {             validations: {               email: [                 orm.enforce.unique(&quot;Email already taken!&quot;),                 orm.enforce.unique({ ignoreCase: true }),                   orm.enforce.notEmptyString()                 ],                 password: orm.enforce.notEmptyString()             },           id: &quot;id&quot;,           autoFetch: false         }       );       var Conferences = db.define(&quot;conferences&quot;,         {             id          : Number,             title       : String,             description : String,             datetime    : Date,             place       : String,             location    : String,             site        : String,             logo        : String,             facebook    : String,             twitter     : String,             telephone   : String,             cost        : String,             file        : String         },{           id: &quot;id&quot;,           autoFetch: false         }       );       var Decisions = db.define(&quot;decisions&quot;,         {           id            : Number,           decision      : ['go', 'not go', 'favorite'],           user          : Number,           conference_id : Number         },{           id: &quot;id&quot;,           cache: false,           autoFetch: false         }       );        Decisions.hasOne('conference', Conferences, {reverse: 'decision'});     } })); <\/code><\/pre>\n<p>  \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0438 \u043d\u0430 \u043c\u043e\u0435\u043c VPS \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f nginx, \u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 PaaS \u0441\u0430\u043c nodejs \u0441\u0442\u0430\u0442\u0438\u043a\u0443 \u0438 \u043e\u0442\u0434\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0435\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438 \u0441\u0430\u043c \u043a\u043b\u0438\u0435\u043d\u0442. <\/p>\n<pre><code class=\"javascript\">var static_handler = express.static(__dirname + '\/..\/static\/'); app.get(\/^\\\/static(\\\/.*)?$\/, function(req, res, next) { \tif (req.url === '\/static') { \/\/ express static barfs on root url w\/o trailing slash \t\tres.writeHead(302, { 'Location' : req.url + '\/' }); \t\tres.end();                 return; \t}  \treq.url = req.url.substr('\/static'.length); \treturn static_handler(req, res, next); });  var main_handler = express.static(__dirname + '\/..\/client\/www\/'); app.get(\/^\\\/(.*)$\/, function(req, res, next) { \tif(req.url == '\/cordova.js'){ \t\treturn res.send(''); \t}  \tif(!req.url){ \t\treq.url = 'index.html'; \t} \treturn main_handler(req, res, next); }); <\/code><\/pre>\n<p>  \u0424\u0430\u0439\u043b cordova.js \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f phonegap`\u043e\u043c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441 \u0436\u0435\u043b\u0435\u0437\u043e\u043c \u0438 \u043f\u0440\u043e\u0447\u0438\u0435, \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0444\u0438\u0447\u0438. \u0412 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u041e\u0421 \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<pre><code class=\"javascript\">app.use(function(req, res, next) {     res.header('Access-Control-Allow-Origin', '*');     res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');     res.header('Access-Control-Allow-Headers',  cfg.header+', Content-Type');     res.header('Access-Control-Expose-Headers', cfg.header+', Content-Type');      if (req.method == 'OPTIONS') {         res.send(200);     }     else {         next();     } });  swagger.setAppHandler(app); swagger.addModels(models); controllers.init(swagger); swagger.configure(cfg.basePath, &quot;0.1&quot;); \/\/ Serve up swagger ui at \/docs via static route var docs_handler = express.static(__dirname + '\/..\/documentation\/swagger\/'); app.get(\/^\\\/docs(\\\/.*)?$\/, function(req, res, next) { \tif (req.url === '\/docs') { \/\/ express static barfs on root url w\/o trailing slash \t\tres.writeHead(302, { 'Location' : req.url + '\/' }); \t\tres.end(); \t\treturn; \t} \t\/\/ take off leading \/docs so that connect locates file correctly \treq.url = req.url.substr('\/docs'.length); \treturn docs_handler(req, res, next); }); <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0441\u044f API \u043e\u0442\u0434\u0430\u044e\u0442\u0441\u044f cross-origin resource sharing headers. \u041f\u043e\u0442\u043e\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0432\u0430\u0433\u0435\u0440\u0430. \u0422\u0443\u0442 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430<\/p>\n<pre><code class=\"javascript\">swagger.addModels(models); controllers.init(swagger); <\/code><\/pre>\n<p>  \u042d\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e \u0434\u043e\u0434\u0430\u044e\u0442\u0441\u044f, \u044d\u0442\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0430\u043d\u0430\u043b\u043e\u0433 ViewModel \u0438 \u043d\u0438\u043d\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043c\u043e\u0434\u0435\u043b\u044f\u043c, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 orm.js. \u0412 controllers.js \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 action\u2019\u043e\u0432. \u041f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<pre><code class=\"javascript\">swagger.addGET(conferences.get); swagger.addGET(conferences.list); swagger.addPOST(conferences.decision); swagger.addDELETE(conferences.reject); <\/code><\/pre>\n<p>  \u041a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f action. \u0420\u0430\u0441\u043f\u0438\u0448\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438 \u043f\u043e id.<\/p>\n<pre><code class=\"javascript\">var get = {   'spec': {     &quot;description&quot; : &quot;Get conference by id&quot;,     &quot;path&quot; : &quot;\/conferences.{format}\/{id}&quot;,     &quot;notes&quot; : &quot;Get conference&quot;,     &quot;summary&quot; : &quot;Get conference&quot;,     &quot;method&quot;: &quot;GET&quot;,     &quot;responseClass&quot; : &quot;Conference&quot;,     &quot;nickname&quot; : &quot;conference&quot;   },   'action': function (req,res) {      if (!req.params.id) {         throw swagger.errors.invalid('id'); }       var id = parseInt(req.params.id);      req.db.models.conferences.get(id, function(err, conference){       if(err){         res.send(500, JSON.stringify({code: 500, header: 'Internal Server Error', message: JSON.stringify(err)}));       }else{         if(conference){           if(conference.file){             conference.file = '\/static\/' + conference.file;           }           if(req.user){             conference.getDecision({user: req.user}, function(err, decision){               if(err){                 res.send(500, JSON.stringify(err));               }else{                 conference.decision = decision.pop();                 res.send(200, JSON.stringify(conference));               }             });           }else{             res.send(200, JSON.stringify(conference));           }         }else{           throw swagger.errors.notFound('conference');         }       }     });   } }; <\/code><\/pre>\n<p>  \u0412 \u00abspec\u00bb \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u043e \u0442\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u00abpath\u00bb, \u0442\u043e\u0435\u0441\u0442\u044c url, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 express \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e \u2014 action. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0442\u043e \u043d\u0435 \u043b\u044e\u0431\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0431\u0435\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0448\u0438\u0440\u044c, \u0441\u043a\u0430\u0436\u0443 \u0441\u0440\u0430\u0437\u0443, \u0447\u0442\u043e node-orm2 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0442\u0430\u043a \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0415\u0441\u043b\u0438 \u043a \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u044b \u0444\u0430\u0439\u043b\u044b, \u0442\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u044c. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d \u0438\u0449\u0435\u0442\u0441\u044f \u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 http \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u043e \u0441\u043a\u0430\u0436\u0443 \u0447\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u044e, \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u0435 REST: \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0442\u044c has-one \u043c\u043e\u0434\u0435\u043b\u044c \u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c id, \u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u0443\u0436\u0435 \u043f\u0443\u0441\u0442\u044c \u0441\u0430\u043c \u0448\u043b\u0435\u0442 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441, \u0435\u0441\u043b\u0438 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e.<br \/>  \u041d\u0430 \u044d\u0442\u043e\u043c, \u0434\u0443\u043c\u0430\u044e, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 swagger-node-express \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430\u0447\u0430\u043b \u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0432\u0438\u0434 \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f, \u043a\u0443\u0434\u0430 \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043d \u0436\u0438\u043b \u043d\u0430 \u043c\u043e\u0435\u043c VPS, \u043d\u043e \u044f \u0442\u0430\u043c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u0441\u0435 \u043b\u0430\u043c\u0430\u044e, \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 PaaS. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0431\u043b\u0430\u043a\u0430 \u044d\u0442\u043e \u043c\u043e\u0434\u043d\u043e, \u0430 \u0435\u0449\u0435 \u0432\u0435\u0441\u0435\u043b\u043e. \u041a\u0441\u0442\u0430\u0442\u0438, \u043c\u043d\u043e\u0433\u0438\u0435 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0435 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u044b, \u043f\u0440\u0438\u0447\u0435\u043c \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0435\u0437 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0445\u043e\u0441\u0442\u0438\u0442\u044c \u0441 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. <br \/>  \u0425\u043e\u0442\u044f \u044f \u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 openshift, \u043d\u043e \u0441\u0430\u043c \u044f \u043a \u043d\u0438\u043c \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043d\u043e\u0448\u0443\u0441\u044c \u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0430\u0445 \u0431\u0443\u0434\u0443\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438(\u0432\u0441\u0435 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a git push). \u0412\u044b\u0431\u0440\u0430\u043b \u044f \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e.<br \/>  \u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u044b \u044d\u0442\u043e\u0433\u043e \u0435\u0449\u0435 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u041f\u043e\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442, \u0432 \u0438\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044d\u0442\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u044f \u0445\u043e\u0447\u0443 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0430\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0435\u0449\u0438. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u0445\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0433\u0434\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u0437\u0430\u0442\u043e\u0447\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u0434 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0445\u043e\u0441\u0442\u0438\u043d\u0433. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u0435\u0441\u044c \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0435\u0440\u0435\u0434 \u0434\u0435\u043f\u043b\u043e\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 server.js, \u0434\u043e\u0434\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u0442\u0430\u0442\u0438\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 memcached \u0441\u0435\u0440\u0432\u0435\u0440.<br \/>  \u042f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u043b client\/www \u0432 server\/www \u0438 \u0442\u0443\u0434\u0430 \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441\u043e \u0441\u0442\u0430\u0442\u0438\u043a\u043e\u0439, \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u043e\u0439 \u043a \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u044f\u043c, \u0438 \u0441\u0432\u0430\u0433\u0435\u0440. \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u043e\u0432\u044b\u0439 static.js.<\/p>\n<pre><code class=\"javascript\">var static_handler = express.static(__dirname + '\/www\/static\/'); app.get(\/^\\\/static(\\\/.*)?$\/, function(req, res, next) {   if (req.url === '\/static') { \/\/ express static barfs on root url w\/o trailing slash     res.writeHead(302, { 'Location' : req.url + '\/' });     res.end();     return;   }   \/\/ take off leading \/docs so that connect locates file correctly   req.url = req.url.substr('\/docs'.length);   return static_handler(req, res, next); });  var main_handler = express.static(__dirname + '\/www\/'); app.get(\/^\\\/(.*)$\/, function(req, res, next) {    if(req.url == '\/cordova.js'){     return res.send('');   }    if(!req.url){     req.url = 'index.html';   }   return main_handler(req, res, next); }); <\/code><\/pre>\n<p>  \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043f\u043e\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0439\u0442\u0435\u0441\u044c \u043d\u0430\u0441\u0447\u0435\u0442 SQL\/no-SQL \u0431\u0430\u0437, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0430\u0437\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0430 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445, openshift \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0446\u0435\u043b\u044b\u0439 \u0441\u043b\u043e\u0442, \u0430 \u0438\u0445 \u0438 \u0442\u0430\u043a \u043c\u0430\u043b\u043e. Memcached \u044f \u043e\u0442\u0434\u0430\u043b \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443 <a href=\"http:\/\/garantiadata.com\">garantiadata.com<\/a>, \u0433\u0434\u0435 \u0442\u043e\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043b \u0442\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442. \u0423 \u043c\u0435\u043d\u044f \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c 2 \u0441\u043b\u043e\u0442\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u0432\u0447\u0435\u0440\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u043a\u0437\u0435\u043f\u043b\u044f\u0440 \u043d\u043e\u0434\u044b \u0442\u043e\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f, \u0447\u0442\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0440\u0430\u0434\u043e\u0432\u0430\u043b\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u043d\u0435 \u0431\u044b\u043b \u0443\u0432\u0435\u0440\u0435\u043d \u0447\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e.<br \/>  \u0418 \u0434\u0430, \u0441\u0430\u043c \u0434\u0435\u043f\u043b\u043e\u0439.<\/p>\n<pre><code class=\"bash\">git add --all; git commit -m 'commit'; git push origin master <\/code><\/pre>\n<p>  \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c origin, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 openshift. \u0422\u0430\u043a \u0436\u0435 \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u0432\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\/\u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043b\u0443\u0436\u0448\u043a\u0438.<\/p>\n<pre><code class=\"javascript\">exports.listen = process.env.OPENSHIFT_NODEJS_PORT || 8080; exports.ipaddr = process.env.OPENSHIFT_NODEJS_IP || &quot;127.0.0.1&quot;; <\/code><\/pre>\n<p>  \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/myconfs-peinguin.rhcloud.com\/haproxy-status\/\">\u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c<\/a>, \u043f\u0440\u0438 git push \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u043b\u043e\u0433. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u043f\u043e ssh \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c tail_all.<br \/>  \u0427\u0435\u0440\u0435\u0437 ssh \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u0411\u0414, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0435\u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"bash\">echo $OPENSHIFT_POSTGRESQL_DB_URL <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435, \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435, \u0432\u0441\u0435 \u0449\u0430\u0441\u043b\u0438\u0432\u044b. \u041a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430, \u0440\u0430\u0434 \u043a\u0440\u0438\u0442\u0438\u043a\u0435 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\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=\"http:\/\/habrahabr.ru\/post\/200356\/\"> http:\/\/habrahabr.ru\/post\/200356\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c8c\/465\/1b0\/c8c4651b03cb9d0789cd33ed8b057440.png\" alt=\"image\" align=\"left\"\/>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0438 \u043e\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0435 openshift.  <\/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-200356","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/200356","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=200356"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/200356\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}