Emygdio February 2016

CppCMS-Embedded 404

I am trying a simple example with CppCms and I would like to execute all my applications relative to the web application root. I don't want execute the application relative to the script path. Ex localhost: 8080/script-path/relative-path-to-my-application, and instead of this, I would like the path for my application would be like: localhost: 8080/relative-path-to-my-application. I would like to execute this application using the CppCMS-Embedded. I am trying a super simple example and I had no success. All the time I try the root url (http://localhost:8080/) I get a 404 error like 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 the code and config files that I 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 ";
               

Answers


Emygdio February 2016

After some threads in the CppCms community, Artyom Beilis opened my mind for this issue. All the time that I requested the root url like that http://domain.com/, I got a 404 error due to that the CppCms always expects at least some mapping that is not empty, like "/" or any other string that start with "/" . The correct way is always to map to something that start with "/". A good solution proposed by Artyom Beilis is to keep the url's rewrite in the same form like the tutorial: How to run the application at the root of the web server. And add a mapping that is not empty that matches with the default url, like that:

 dispatcher().assign("/",&my_app::well_come,this);
 mapper().assign("well_come","/");

This solution works pretty well for me =;)

Post Status

Asked in February 2016
Viewed 2,366 times
Voted 11
Answered 1 times

Search




Leave an answer