add HttpView csp file in example
This commit is contained in:
parent
30ab716c6b
commit
388f97d729
|
@ -1,3 +1,20 @@
|
|||
link_libraries(drogon trantor uuid pthread jsoncpp)
|
||||
|
||||
FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/static_link_example/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
message(STATUS "cspFile:" ${cspFile})
|
||||
EXEC_PROGRAM(basename ARGS "-s .csp ${cspFile}" OUTPUT_VARIABLE classname)
|
||||
message(STATUS "view classname:" ${classname})
|
||||
add_custom_command(OUTPUT ${classname}.h ${classname}.cc
|
||||
COMMAND drogon_ctl
|
||||
ARGS create view ${cspFile}
|
||||
DEPENDS ${cspFile}
|
||||
VERBATIM )
|
||||
set(VIEWSRC ${VIEWSRC} ${classname}.cc)
|
||||
endforeach()
|
||||
|
||||
|
||||
AUX_SOURCE_DIRECTORY(static_link_example DIR_STATIC)
|
||||
add_executable(webapp ${DIR_STATIC})
|
||||
|
||||
add_executable(webapp ${DIR_STATIC} ${VIEWSRC})
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<%c++ std::string title=@@.get<std::string>("title");%>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title><%c++ $$<<title;%> clone</title>
|
||||
</head>
|
||||
<body>
|
||||
<footer>
|
||||
<span>CopyRight@2017 All Rights Reserved</span>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,9 @@
|
|||
#include "TestViewCtl.h"
|
||||
void TestViewCtl::asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)
|
||||
{
|
||||
//write your application logic here
|
||||
drogon::HttpViewData data;
|
||||
data.insert("title",std::string("TestView"));
|
||||
std::unique_ptr<HttpResponse> res=std::unique_ptr<HttpResponse>(drogon::HttpResponse::newHttpViewResponse("TestViewClone",data));
|
||||
callback(*res);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpSimpleController.h>
|
||||
using namespace drogon;
|
||||
class TestViewCtl:public drogon::HttpSimpleController<TestViewCtl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)override;
|
||||
PATH_LIST_BEGIN
|
||||
//list path definations here;
|
||||
//PATH_ADD("/path","filter1","filter2",...);
|
||||
PATH_ADD("/view");
|
||||
PATH_LIST_END
|
||||
};
|
Loading…
Reference in New Issue