{"id":328291,"date":"2022-01-20T03:00:19","date_gmt":"2022-01-20T03:00:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=328291"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=328291","title":{"rendered":"<span>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0421++<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0421\/\u0421++ \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0435\u043a\u0430 Nginx+fastcgi. \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u043c, \u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0430\u0439\u0442\u0430\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u043a \u043e\u0442\u0434\u0430\u0447\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430. \u0415\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0430\u0440\u0430\u044f, \u043d\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f <a href=\"https:\/\/habr.com\/ru\/post\/154187\/\">habr.com\/ru\/post\/154187<\/a> \u0421 \u0442\u0435\u0445 \u043f\u043e\u0440 \u043f\u0440\u043e\u0448\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0434\u0430 \u0438 \u0432\u044b\u0448\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u044b \u0421++. \u042f \u0445\u043e\u0447\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430.<a name=\"habracut\"><\/a><br \/>  \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043d\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u041d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c nginx \u043d\u0430 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438\u043b\u0438 \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u043e\u0435. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Ubuntu 20.04, Codeblocks. \u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0433\u043e nginx, \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 libfcgi-dev. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043e\u0442\u0434\u0430\u0447\u0443 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u043e\u0442\u0434\u0430\u0447\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445(\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445) \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0414\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u043a\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 url, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430. Nginx \u0442\u043e\u0436\u0435 \u0443\u043c\u0435\u0435\u0442 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043d\u043e \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443. \u0412 \u043d\u0430\u0448\u0435\u043c \u0436\u0435 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c.<br \/>  \u0412 Project\u2192Build options->Linker settings \u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 lpthread, lfcgi. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.  <\/p>\n<pre><code class=\"cpp\">class web_backend {     public:     \/\/\/PATH_MAX \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0443\u043b\u044c     std::string path; \/\/\/\u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c     char *ip_addr=\"127.0.0.1:9000\";     std::string html_relative_path{\"\/html\"};     std::vector&lt;char*> files;      web_backend()     {         char buf[PATH_MAX]; \/\/\/PATH_MAX \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0443\u043b\u044c         get_full_path(\"bin\", buf);         path.append(buf);         path=path+html_relative_path;         files=get_all_string_from_path((char*)path.c_str());         create_fastcgi_threads(ip_addr);     }     ~web_backend()     {         for(char *str: files)         {             free(str);         }     }     private:     int THREAD_COUNT=sysconf(_SC_NPROCESSORS_ONLN);     void get_full_path(char *relatve_path, char *absolute_path);     int create_fastcgi_threads(char *ip_addr);     std::vector&lt;char*> get_all_string_from_path(char* html_path);     std::string urlencode(const std::string &amp;s);     std::string urlDecode(std::string &amp;SRC);      static int threadFunction(int socketId, char* html_path, std::vector&lt;char*> *files);     static void generate_pages_from_uri(FCGX_Request *request, char *uri, char* html_path, std::vector&lt;char*> *files);     static int add_all_path_for_send(FCGX_Request *request, char *uri, char *html_path, std::vector&lt;char*> *files); }; <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a static \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043e\u0431\u0449\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c.<br \/>  \u0422\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u0438\u0431\u043e \u043e\u0442\u0432\u044f\u0437\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043b\u0438\u0431\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0435\u0451 \u043a\u0430\u043a static. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0451\u043d. urlDecode\/urlencode \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f, \u043d\u043e \u043d\u0443\u0436\u043d\u044b \u0432 post\/get \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b. \u042f \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432 php \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041f\u0443\u0442\u0438 \u043c\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0430\u043f\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0442\u043e \u043d\u0443\u0436\u043d\u043e<br \/>  $cd \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439_\u043f\u0443\u0442\u044c_\u043a_\u043f\u0430\u043f\u043a\u0435_\u0441_\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c  <\/p>\n<pre><code class=\"bash\">$cd \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439_\u043f\u0443\u0442\u044c_\u043a_\u043f\u0430\u043f\u043a\u0435_\u0441_\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c $.\/bin\/Release\/web_C++ <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a(\u0442\u043e\u0447\u043d\u0435\u0435 \u0432\u0435\u043a\u0442\u043e\u0440) url\/\u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0441\u0430\u043c\u0438 \u043f\u043e\u043b\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0445 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043d\u0438\u044f  <\/p>\n<pre><code class=\"cpp\">int web_backend::add_all_path_for_send(FCGX_Request *request, char *uri, char *html_path, std::vector&lt;char*> *files) {     for(char *str: *files)     {         \/\/\/\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e         char *str_temp=\"\/index.html\"; \/\/\/\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f index.html         if(!strcmp(uri, \"\/\"))         {             goto start;         }         str_temp=str;         if(!strcmp(uri, str_temp))         {             start:             std::string filename{html_path};             filename+=str_temp;             std::ifstream istrm(filename, std::ios::binary);             if (istrm.is_open())             {                 std::stringstream extension;                 extension&lt;&lt;std::filesystem::path(filename.c_str()).extension();                 if(extension.str()!=\".mstch\")                 {                     istrm.seekg (0, istrm.end);                     std::streampos size = istrm.tellg();                     istrm.seekg (0, istrm.beg);                     char *memblock = new char [size];                     istrm.read (memblock, size);                     istrm.close();                     FCGX_PutStr(memblock, size, request->out);                     delete[] memblock;                     return 0;                 }                 else                 {                     \/\/\/\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438                 }             }             else std::cout &lt;&lt; \"Unable to open file\";         }     }     return 0; } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f html_path \u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u043f\u0430\u043f\u043a\u0435 \u0441 html \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438, \u0432\u0435\u043a\u0442\u043e\u0440 \u0441 \u0441\u0438\u0448\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u2014 \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u0443\u0442\u0438. \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043f\u043e for(char *str: *files), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u044b \u0432 \u0421++20. goto \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e index.html \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u0442\u0434\u0430\u0447\u0430 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0446\u0435\u043b\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c, \u0445\u043e\u0442\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0441\u0442\u0438 \u043e\u0442\u0434\u0430\u0447\u0443 \u0447\u0430\u0441\u0442\u044f\u043c\u0438, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 nginx. FCGX_PutStr \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432\u043e\u043e\u0431\u0449\u0435 \u043a \u043b\u044e\u0431\u044b\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0441\u0432\u043e\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435. \u041f\u043e \u0437\u0430\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u044b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c .mstch, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u043e\u0442 mustache. \u0428\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u044f \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u043f\u0430\u043f\u043a\u0443 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c ( <a href=\"https:\/\/github.com\/no1msd\/mstch\" rel=\"nofollow noopener noreferrer\">github.com\/no1msd\/mstch<\/a>) \u0438 \u0441\u043e\u0437\u0434\u0430\u043b \u043d\u043e\u0432\u0443\u044e \u0446\u0435\u043b\u044c \u0441\u0431\u043e\u0440\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 Project->Properties->Build targets. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u0430\u044f \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 -fPIC. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u043f\u0430\u043f\u043a\u0438 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0431\u043e\u0440\u043a\u0438 CodeBlocks, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e-\u0432\u0438\u0434\u0438\u043c\u043e\u043c\u0443 realpath (stdlib). mustache \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 boost \u0438 \u0438\u043c\u0435\u0435\u0442 \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u0435\u00bb \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u044b\u043c \u043e\u0431\u0445\u043e\u0434\u043d\u043e\u043c \u0438 \u043e\u0442\u0434\u0430\u0447\u0435\u0439 \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c.  <\/p>\n<pre><code class=\"cpp\">const mstch::node&amp; render_context::find_node(     const std::string&amp; token,     std::list&lt;node const*> current_nodes) {   if (token != \".\" &amp;&amp; token.find('.') != std::string::npos)     return find_node(token.substr(token.rfind('.') + 1),         {&amp;find_node(token.substr(0, token.rfind('.')), current_nodes)});   else     for (auto&amp; node: current_nodes)       if (visit(has_token(token), *node))         return visit(get_token(token, *node), *node);   return null_node; } <\/code><\/pre>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043e\u0431\u0445\u043e\u0434 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u0437\u043b\u043e\u0432 \u0432 std::string.<br \/>  \u0414\u0430, \u0441\u0430\u043c\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 mustache \u0442\u044f\u0436\u0435\u043b\u043e\u0432\u0430\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0438\u043f\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u0432 Readme, \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432  <\/p>\n<pre><code class=\"cpp\">std::string view{\"{{#names}}{{> column}}{{\/names}}\"}; std::string user_view{\"&lt;strong>{{name}}&lt;\/strong>\"}; mstch::map context{   {\"names\", mstch::array{     mstch::map{{\"name\", std::string{\"Chris\"}}},     mstch::map{{\"name\", std::string{\"Mark\"}}},     mstch::map{{\"name\", std::string{\"Scott\"}}},   }} }; std::cout &lt;&lt; mstch::render(view, context, {{\"column\", user_view}}) &lt;&lt; std::endl; <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u0443-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f  <\/p>\n<pre><code class=\"cpp\">std::string view{\"Hello {{lambda}}!\"}; mstch::map context{   {\"lambda\", mstch::lambda{[]() -> mstch::node {     return std::string{\"World\"};   }}} }; std::cout &lt;&lt; mstch::render(view, context) &lt;&lt; std::endl; <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u0433\u043e\u0432. \u0412\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439  <\/p>\n<pre><code class=\"cpp\">mstch::config::escape = [](const std::string&amp; str) -> std::string {   return str; }; mstch::config::escape=nullptr; <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043a \u043e\u0442\u0434\u0430\u0447\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430.  <\/p>\n<pre><code class=\"cpp\">void web_backend::generate_pages_from_uri(FCGX_Request *request, char *uri, char* html_path, std::vector&lt;char*> *files) {     FCGX_PutS(\"\\n\", request->out);     add_all_path_for_send(request, uri, html_path, files);     \/\/\/\u0437\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 post\/get \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 } <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 post\/get \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u043f\u0430\u043f\u043a\u0438 \u0438 \u043f\u043e\u0434\u043f\u0430\u043f\u043a\u0438 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0451\u043d \u0444\u0430\u0439\u043b\u043e\u0432, \u043f\u0440\u0438\u0447\u0451\u043c \u043f\u0443\u0442\u0438 \u0443\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u0434\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0443\u0442\u0451\u043c \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043f\u0440\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 dir_entry.path().c_str()+strlen(html_path)   <\/p>\n<pre><code class=\"cpp\">std::vector&lt;char*> web_backend::get_all_string_from_path(char* html_path) {     std::vector &lt;char*> vc;     const std::filesystem::path sandbox(html_path);     namespace fs = std::filesystem;     if(fs::exists(sandbox))     {         for(std::filesystem::directory_entry const&amp; dir_entry: std::filesystem::recursive_directory_iterator{sandbox})         {             if(fs::is_regular_file(dir_entry))             {                 vc.emplace_back(strdup(dir_entry.path().c_str()+strlen(html_path)));             }         }     }     return vc; } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0433\u043e \u043a\u0430\u043a\u0438\u0445 \u0442\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, CRUD \u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f.  <\/p>\n<pre><code class=\"nginx\">server {  listen       80 default_server; server_name localhost;  location \/ {  fastcgi_pass 127.0.0.1:9000; include fastcgi_params;  } } <\/code><\/pre>\n<p>  <a href=\"https:\/\/github.com\/SanyaZ7\/webCpp\" rel=\"nofollow noopener noreferrer\">github.com\/SanyaZ7\/webCpp<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><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:\/\/habr.com\/ru\/post\/645925\/\"> https:\/\/habr.com\/ru\/post\/645925\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0421\/\u0421++ \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0435\u043a\u0430 Nginx+fastcgi. \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u043c, \u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0430\u0439\u0442\u0430\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u043a \u043e\u0442\u0434\u0430\u0447\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430. \u0415\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0430\u0440\u0430\u044f, \u043d\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f <a href=\"https:\/\/habr.com\/ru\/post\/154187\/\">habr.com\/ru\/post\/154187<\/a> \u0421 \u0442\u0435\u0445 \u043f\u043e\u0440 \u043f\u0440\u043e\u0448\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0434\u0430 \u0438 \u0432\u044b\u0448\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u044b \u0421++. \u042f \u0445\u043e\u0447\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430.<\/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-328291","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/328291","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=328291"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/328291\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=328291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=328291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=328291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}