c++ - CppCMS-Embedded 404 -
i trying simple example cppcms , execute applications relative web application root. don't want execute application relative script path. ex localhost: 8080/script-path/relative-path-to-my-application, , instead of this, path application like: localhost: 8080/relative-path-to-my-application. execute application using cppcms-embedded. trying super simple example , had no success. time try root url (http://localhost:8080/) 404 error that:
connection close content-encoding gzip content-type text/html; charset=utf-8 server cppcms-embedded/1.1.0 x-powered-by cppcms/1.1.0 status 404 not found accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-encoding gzip, deflate accept-language en-us,en;q=0.5 cache-control max-age=0 connection keep-alive cookie _ga=ga1.1.541474771.1454701631 host localhost:8080 user-agent mozilla/5.0 (x11; fedora; linux x86_64; rv:44.0) gecko/20100101 firefox/44.0
below code , config files made:
main.cpp:
#include <cppcms/application.h> #include <cppcms/applications_pool.h> #include <cppcms/service.h> #include <cppcms/http_response.h> #include <cppcms/url_dispatcher.h> #include <cppcms/url_mapper.h> #include <iostream> #include "content.h" class my_app : public cppcms::application{ public: my_app(cppcms::service& s) : cppcms::application(s){ dispatcher().assign("",&my_app::well_come,this); mapper().assign(""); mapper().root(""); } void well_come(){ content::index ci; ci.message = "hello "; render("index",ci); } }; int main(int argc,char ** argv){ try{ cppcms::service srv(argc,argv); srv.applications_pool().mount( cppcms::applications_factory<my_app>() ); srv.run(); }catch(std::exception const & e){ std::cerr<<e.what()<<std::endl; } }
config.js:
{ "http" : { "script" : "/mb.fcgi", "rewrite" : [ { "regex" : "/media(/.*)?", "pattern" : "$0" }, { "regex" : ".*" , "pattern" : "/mb.fcgi$0" } ] }, "service": { "api":"http", "port":8080 }, "views" : { "paths" : [ "./" ], "skins" : [ "my_app"], }, }
index.tmpl
<% c++ #include "content.h" %> <% skin my_app %> <% view index uses content::index %> <% template render()%> <html> <body> <h1><%= message %> world!</h1> </body> </html> <% end template %> <% end view %> <% end skin %>
content.h
#include <cppcms/view.h> namespace content{ struct index : public cppcms::base_content{ std::string message; }; }
what's missing in configurations? why cppcms-embedded not routing web application root . thanks.
after threads in cppcms community, artyom beilis opened mind issue. time requested root url http://domain.com/, got 404 error due cppcms expects @ least mapping not empty, "/" or other string start "/" . correct way map start "/". solution proposed artyom beilis keep url's rewrite in same form tutorial: how run application @ root of web server. , add mapping not empty matches default url, that:
dispatcher().assign("/",&my_app::well_come,this); mapper().assign("well_come","/");
this solution works pretty me =;)
Comments
Post a Comment