1

CppCms を使用して簡単な例を試しています。すべてのアプリケーションを Web アプリケーション ルートに対して相対的に実行したいと考えています。スクリプト パスを基準にしてアプリケーションを実行したくありません。Ex localhost: 8080/script-path/relative-path-to-my-application の代わりに、アプリケーションのパスを次のようにしたいと思います: localhost: 8080/relative-path-to-my-application. CppCMS-Embedded を使用してこのアプリケーションを実行したいと考えています。私は非常に単純な例を試していますが、成功しませんでした。ルート URL ( http://localhost:8080/ ) を試すたびに、次のような 404 エラーが発生します。

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

私が作成したコードと構成ファイルの下:

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;
   };
}

構成に欠けているものは何ですか? CppCMS-Embedded が Web アプリケーション ルートにルーティングされない理由。ありがとう。

4

1 に答える 1