| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,7 @@ deploy-latest-docker: | |||
| 59 | 59 | cmake .. \ | |
| 60 | 60 | -DEXPRESSCPP_ENABLE_COVERAGE=ON \ | |
| 61 | 61 | -DEXPRESSCPP_BUILD_EXAMPLES=ON \ | |
| 62 | + -DEXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER=ON \ | ||
| 62 | 63 | -DEXPRESSCPP_BUILD_TESTS=ON | |
| 63 | 64 | - make -j2 | |
| 64 | 65 | - | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,6 +102,7 @@ | |||
| 102 | 102 | }, | |
| 103 | 103 | "cmake.configureSettings": { | |
| 104 | 104 | "EXPRESSCPP_BUILD_TESTS": true, | |
| 105 | - "EXPRESSCPP_BUILD_EXAMPLES": true | ||
| 106 | - } | ||
| 105 | + "EXPRESSCPP_BUILD_EXAMPLES": true, | ||
| 106 | + "EXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER": true | ||
| 107 | + } | ||
| 107 | 108 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,11 +63,12 @@ if(MSVC) | |||
| 63 | 63 | message(STATUS "using msvc") | |
| 64 | 64 | add_definitions(-D_WIN32_WINNT=0x600) | |
| 65 | 65 | add_definitions(-DBOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT) | |
| 66 | - if (MSVC_VERSION GREATER_EQUAL "1900") | ||
| 66 | + if(MSVC_VERSION GREATER_EQUAL "1900") | ||
| 67 | 67 | include(CheckCXXCompilerFlag) | |
| 68 | - CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported) | ||
| 69 | - if (_cpp_latest_flag_supported) | ||
| 70 | - add_compile_options("/std:c++latest") | ||
| 68 | + check_cxx_compiler_flag("/std:c++latest" | ||
| 69 | + _cpp_latest_flag_supported) | ||
| 70 | + if(_cpp_latest_flag_supported) | ||
| 71 | + add_compile_options("/std:c++latest") | ||
| 71 | 72 | endif() | |
| 72 | 73 | endif() | |
| 73 | 74 | else() | |
@@ -157,6 +158,7 @@ else() | |||
| 157 | 158 | endif() | |
| 158 | 159 | ||
| 159 | 160 | if(EXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER) | |
| 161 | + message(STATUS "building with static file provider") | ||
| 160 | 162 | add_definitions(-DEXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER) | |
| 161 | 163 | endif() | |
| 162 | 164 | ||
@@ -221,8 +223,7 @@ target_compile_options( | |||
| 221 | 223 | ${PROJECT_NAME} | |
| 222 | 224 | PRIVATE $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall> | |
| 223 | 225 | $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-pedantic> | |
| 224 | - $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wextra> | ||
| 225 | - ) | ||
| 226 | + $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wextra>) | ||
| 226 | 227 | if(CLANG_TIDY_EXE) | |
| 227 | 228 | set_target_properties(${PROJECT_NAME} | |
| 228 | 229 | PROPERTIES CXX_CLANG_TIDY | |
@@ -233,11 +234,11 @@ if(EXPRESSCPP_USE_STACKTRACE) | |||
| 233 | 234 | message(STATUS "using boost stack trace") | |
| 234 | 235 | add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE) | |
| 235 | 236 | add_definitions(-DEXPRESSCPP_USE_STACKTRACE) | |
| 236 | - target_compile_options(${PROJECT_NAME} | ||
| 237 | - PUBLIC -fno-pie | ||
| 238 | - $<$<CXX_COMPILER_ID:GNU>:-no-pie> | ||
| 239 | - $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-fPIC> | ||
| 240 | - ) | ||
| 237 | + target_compile_options( | ||
| 238 | + ${PROJECT_NAME} | ||
| 239 | + PUBLIC -fno-pie | ||
| 240 | + $<$<CXX_COMPILER_ID:GNU>:-no-pie> | ||
| 241 | + $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-fPIC>) | ||
| 241 | 242 | target_link_libraries(${PROJECT_NAME} | |
| 242 | 243 | PUBLIC # for boost stackstrace | |
| 243 | 244 | ${CMAKE_DL_LIBS}) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,15 @@ | |||
| 1 | 1 | #!/bin/bash | |
| 2 | 2 | ||
| 3 | - export CC=/usr/bin/gcc-9 | ||
| 4 | - export CXX=/usr/bin/g++-9 | ||
| 3 | + # export CC=/usr/bin/gcc-9 | ||
| 4 | + # export CXX=/usr/bin/g++-9 | ||
| 5 | 5 | rm -rf _build | |
| 6 | 6 | mkdir _build | |
| 7 | 7 | cd _build | |
| 8 | - cmake .. \ | ||
| 8 | + cmake .. -GNinja \ | ||
| 9 | 9 | -DEXPRESSCPP_BUILD_EXAMPLES=ON \ | |
| 10 | 10 | -DEXPRESSCPP_BUILD_TESTS=ON | |
| 11 | 11 | ||
| 12 | - make -j4 | ||
| 12 | + cmake --build . -j | ||
| 13 | 13 | ||
| 14 | 14 | # docker build -t registry.gitlab.com/expresscpp/expresscpp/ci_gcc8 -f docker/ci_gcc8/Dockerfile . | |
| 15 | 15 | # docker push registry.gitlab.com/expresscpp/expresscpp/ci_gcc8 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,5 +27,5 @@ add_example(simple_rest_router_server) | |||
| 27 | 27 | add_example(error_handler) | |
| 28 | 28 | ||
| 29 | 29 | if(EXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER) | |
| 30 | - add_example(simple_static_file_server) | ||
| 30 | + add_example(static_file_server) | ||
| 31 | 31 | endif() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,13 +7,13 @@ | |||
| 7 | 7 | ||
| 8 | 8 | #include "expresscpp/expresscpp.hpp" | |
| 9 | 9 | ||
| 10 | - int main() { | ||
| 11 | - std::cout << "Hello World!" << std::endl; | ||
| 10 | + using namespace expresscpp; | ||
| 12 | 11 | ||
| 13 | - auto expresscpp = std::make_shared<ExpressCpp>(); | ||
| 12 | + int main() { | ||
| 13 | + ExpressCpp expresscpp; | ||
| 14 | 14 | ||
| 15 | 15 | // get a folder to write to | |
| 16 | - std::string doc_root = "/tmp/www"; | ||
| 16 | + const std::string doc_root = "/tmp/www"; | ||
| 17 | 17 | std::filesystem::create_directory(doc_root); | |
| 18 | 18 | ||
| 19 | 19 | // create a html index file | |
@@ -34,11 +34,21 @@ int main() { | |||
| 34 | 34 | index_html_file.close(); | |
| 35 | 35 | ||
| 36 | 36 | // tell express to look for files in this directory | |
| 37 | - expresscpp->Use(expresscpp->GetStaticFileProvider(doc_root)); | ||
| 37 | + expresscpp.Use(expresscpp.GetStaticFileProvider(doc_root)); | ||
| 38 | 38 | ||
| 39 | 39 | // start listening for requests and block until ctrl+C | |
| 40 | 40 | const uint16_t port = 8081u; | |
| 41 | - expresscpp->Listen(port, []() { std::cout << "Example app listening on port " << port << std::endl; }).Block(); | ||
| 41 | + expresscpp | ||
| 42 | + .Listen(port, | ||
| 43 | + [&](auto ec) { | ||
| 44 | + if (ec) { | ||
| 45 | + std::cerr << "ERROR: " << ec.message() << std::endl; | ||
| 46 | + exit(1); | ||
| 47 | + } | ||
| 48 | + std::cout << "Example app listening on port " << port << std::endl; | ||
| 49 | + std::cout << "go to http://localhost:" << port << std::endl; | ||
| 50 | + }) | ||
| 51 | + .Block(); | ||
| 42 | 52 | ||
| 43 | 53 | return 0; | |
| 44 | 54 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,8 +85,6 @@ class ExpressCpp { | |||
| 85 | 85 | std::function<void(const std::error_code)> callback); | |
| 86 | 86 | ||
| 87 | 87 | private: | |
| 88 | - void RegisterPath(const std::string_view path, const HttpMethod method, express_handler_t handler, | ||
| 89 | - const bool is_router = false); | ||
| 90 | 88 | void RegisterPath(const std::string_view path, const HttpMethod method, express_handler_wn_t handler); | |
| 91 | 89 | void Init(); | |
| 92 | 90 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,6 @@ class ExpressCpp; | |||
| 23 | 23 | class Response; | |
| 24 | 24 | class Listener; | |
| 25 | 25 | ||
| 26 | - using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp> | ||
| 27 | 26 | using SessionParser = http::request_parser<http::string_body>; | |
| 28 | 27 | ||
| 29 | 28 | // Handles an HTTP server connection | |
@@ -32,11 +31,11 @@ class Session : public std::enable_shared_from_this<Session> { | |||
| 32 | 31 | ||
| 33 | 32 | public: | |
| 34 | 33 | // Take ownership of the stream | |
| 35 | - Session(tcp::socket socket, ExpressCpp* express_cpp); | ||
| 34 | + Session(boost::asio::ip::tcp::socket socket, ExpressCpp* express_cpp); | ||
| 36 | 35 | ||
| 37 | 36 | ~Session(); | |
| 38 | 37 | ||
| 39 | - tcp::socket socket_; | ||
| 38 | + boost::asio::ip::tcp::socket socket_; | ||
| 40 | 39 | ||
| 41 | 40 | beast::flat_buffer buffer_{8192}; | |
| 42 | 41 | std::shared_ptr<void> res_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,10 @@ | |||
| 1 | 1 | #pragma once | |
| 2 | 2 | ||
| 3 | 3 | #include <filesystem> | |
| 4 | - #include <iostream> | ||
| 4 | + #include <string> | ||
| 5 | 5 | ||
| 6 | 6 | #include "expresscpp/types.hpp" | |
| 7 | + | ||
| 7 | 8 | namespace expresscpp { | |
| 8 | 9 | ||
| 9 | 10 | class StaticFileProvider { | |
@@ -16,8 +17,9 @@ class StaticFileProvider { | |||
| 16 | 17 | ||
| 17 | 18 | private: | |
| 18 | 19 | std::filesystem::path path_to_root_folder_{"/tmp"}; | |
| 19 | - std::string_view doc_root{"/tmp"}; | ||
| 20 | + // std::string_view doc_root{"/tmp"}; | ||
| 20 | 21 | }; | |
| 21 | 22 | ||
| 22 | 23 | typedef std::shared_ptr<StaticFileProvider> StaticFileProviderPtr; | |
| 24 | + | ||
| 23 | 25 | } // namespace expresscpp | |
| Back | FazBrowse Home | New Git URL |
0 commit comments