| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,16 @@ | |||
| 1 | 1 | #!/bin/bash | |
| 2 | 2 | ||
| 3 | + | ||
| 4 | + export CC=/usr/bin/clang-8 | ||
| 5 | + export CXX=/usr/bin/clang++-8 | ||
| 3 | 6 | rm -rf _build | |
| 4 | 7 | mkdir _build | |
| 5 | 8 | cd _build | |
| 6 | 9 | cmake .. -GNinja \ | |
| 7 | 10 | -DEXPRESSCPP_BUILD_EXAMPLES=ON \ | |
| 8 | 11 | -DEXPRESSCPP_BUILD_TESTS=ON \ | |
| 9 | 12 | -DEXPRESSCPP_USE_CONAN_DEPENDENCIES=ON | |
| 13 | + -DEXPRESSCPP_RUN_CLANG_TIDY=ON | ||
| 10 | 14 | ||
| 11 | 15 | cmake --build . -j | |
| 12 | 16 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,8 +9,10 @@ | |||
| 9 | 9 | ||
| 10 | 10 | #include "boost/uuid/uuid_generators.hpp" | |
| 11 | 11 | #include "boost/uuid/uuid_io.hpp" | |
| 12 | + | ||
| 12 | 13 | #include "expresscpp/console.hpp" | |
| 13 | 14 | #include "expresscpp/expresscpp.hpp" | |
| 15 | + #include "expresscpp/middleware/serve_static_provider.hpp" | ||
| 14 | 16 | ||
| 15 | 17 | using namespace expresscpp; | |
| 16 | 18 | ||
@@ -57,7 +59,7 @@ int main() { | |||
| 57 | 59 | assert(std::filesystem::exists(path_to_doc)); | |
| 58 | 60 | } | |
| 59 | 61 | ||
| 60 | - auto p = expresscpp.GetStaticFileProvider(doc_root); | ||
| 62 | + StaticFileProvider p(doc_root); | ||
| 61 | 63 | ||
| 62 | 64 | expresscpp.Use(p); | |
| 63 | 65 | const uint16_t port = 8081u; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | using namespace expresscpp; | |
| 10 | 10 | ||
| 11 | - void LoggerMiddleware(request_t req, response_t /*res*/) { | ||
| 11 | + void LoggerMiddleware(request_t req, response_t /*res*/, next_t /*next*/) { | ||
| 12 | 12 | std::cout << "LOGGER: time: " << req->getTimeStamp() << ", path: " | |
| 13 | 13 | << "\"" << req->getPath() << "\"" | |
| 14 | 14 | << ", method: " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,6 @@ | |||
| 14 | 14 | #include "expresscpp/route.hpp" | |
| 15 | 15 | #include "expresscpp/router.hpp" | |
| 16 | 16 | #include "expresscpp/types.hpp" | |
| 17 | - #include "expresscpp/middleware/serve_static_provider.hpp" | ||
| 18 | 17 | ||
| 19 | 18 | namespace expresscpp { | |
| 20 | 19 | ||
@@ -67,8 +66,6 @@ class ExpressCpp { | |||
| 67 | 66 | ||
| 68 | 67 | void Error(express_handler_wecn_t handler); | |
| 69 | 68 | ||
| 70 | - void Use(handler_t handler); | ||
| 71 | - | ||
| 72 | 69 | /*! | |
| 73 | 70 | * Proxy `Router#Use()` to add middleware to the app router. | |
| 74 | 71 | * See Router#use() documentation for details. | |
@@ -80,14 +77,12 @@ class ExpressCpp { | |||
| 80 | 77 | void Use(std::string_view path, handler_t handler); | |
| 81 | 78 | void Use(std::string_view path, handler_wn_t handler); | |
| 82 | 79 | void Use(std::string_view path, RouterPtr router); | |
| 83 | - void Use(StaticFileProviderPtr static_file_provider); | ||
| 84 | - void Use(std::string_view path, StaticFileProviderPtr static_file_provider); | ||
| 85 | 80 | ||
| 86 | 81 | auto GetBaseRouter(); | |
| 87 | 82 | ||
| 88 | 83 | std::shared_ptr<Route> CreateRoute(const std::string_view); | |
| 89 | 84 | ||
| 90 | - //! called to start listening on port @ref port_ | ||
| 85 | + //! called to start listening on port | ||
| 91 | 86 | ExpressCpp& Listen(const uint16_t port, ready_fn_cb_error_code_t callback); | |
| 92 | 87 | ||
| 93 | 88 | void Run(); | |
@@ -96,8 +91,6 @@ class ExpressCpp { | |||
| 96 | 91 | RouterPtr GetRouter(); | |
| 97 | 92 | RouterPtr GetRouter(std::string_view name); | |
| 98 | 93 | ||
| 99 | - StaticFileProviderPtr GetStaticFileProvider(const std::filesystem::path& path_to_root_folder); | ||
| 100 | - | ||
| 101 | 94 | std::vector<RoutingStack> Stack() const; | |
| 102 | 95 | ||
| 103 | 96 | /** | |
@@ -112,11 +105,9 @@ class ExpressCpp { | |||
| 112 | 105 | std::condition_variable running_cv; | |
| 113 | 106 | bool finished_{false}; | |
| 114 | 107 | std::unique_ptr<Router> router_; | |
| 115 | - std::vector<StaticFileProviderPtr> static_file_providers_; | ||
| 116 | 108 | std::shared_ptr<Listener> listener_; | |
| 117 | 109 | std::vector<Route> routes_; | |
| 118 | 110 | std::size_t threads_{4u}; | |
| 119 | - std::uint16_t port_; | ||
| 120 | 111 | bool error_handler_registered_{false}; | |
| 121 | 112 | express_handler_wecn_t error_handler_; | |
| 122 | 113 | bool listening_{false}; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | #include <string> | |
| 6 | 6 | ||
| 7 | 7 | #include "boost/uuid/uuid.hpp" | |
| 8 | + | ||
| 8 | 9 | #include "expresscpp/layer.hpp" | |
| 9 | 10 | #include "expresscpp/request.hpp" | |
| 10 | 11 | #include "expresscpp/response.hpp" | |
@@ -33,6 +34,7 @@ class Router { | |||
| 33 | 34 | */ | |
| 34 | 35 | void Use(std::string_view path, handler_wn_t handler); | |
| 35 | 36 | void Use(handler_wn_t handler); | |
| 37 | + | ||
| 36 | 38 | void Get(std::string_view path, handler_wn_t handler); | |
| 37 | 39 | void Post(std::string_view path, handler_wn_t handler); | |
| 38 | 40 | void Delete(std::string_view path, handler_wn_t handler); | |
@@ -63,11 +65,6 @@ class Router { | |||
| 63 | 65 | */ | |
| 64 | 66 | std::shared_ptr<Route> CreateRoute(const std::string_view registered_path); | |
| 65 | 67 | ||
| 66 | - std::vector<Route> routes_; | ||
| 67 | - | ||
| 68 | - boost::uuids::uuid uuid_; | ||
| 69 | - std::chrono::system_clock::time_point timestamp_; | ||
| 70 | - | ||
| 71 | 68 | std::string_view GetName() const; | |
| 72 | 69 | ||
| 73 | 70 | std::vector<std::shared_ptr<Layer>> stack() const; | |
@@ -99,8 +96,19 @@ class Router { | |||
| 99 | 96 | */ | |
| 100 | 97 | bool strict{false}; | |
| 101 | 98 | ||
| 99 | + std::vector<Route> routes_; | ||
| 100 | + | ||
| 101 | + //! @brief uuid of the router, for debugging | ||
| 102 | + boost::uuids::uuid uuid_; | ||
| 103 | + | ||
| 104 | + //! @brief creation date of the router, for debugging | ||
| 105 | + std::chrono::system_clock::time_point timestamp_; | ||
| 106 | + | ||
| 107 | + //! @brief name of the router, mostly for debugging | ||
| 102 | 108 | std::string_view name_{"unknown"}; | |
| 109 | + | ||
| 103 | 110 | std::vector<std::shared_ptr<Layer>> stack_; | |
| 111 | + | ||
| 104 | 112 | std::string parent_path_; | |
| 105 | 113 | }; | |
| 106 | 114 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,12 +41,6 @@ std::shared_ptr<Route> ExpressCpp::CreateRoute(const std::string_view registered | |||
| 41 | 41 | return router_->CreateRoute(registered_path); | |
| 42 | 42 | } | |
| 43 | 43 | ||
| 44 | - void ExpressCpp::Use(handler_t handler) { | ||
| 45 | - Console::Debug("using handler for all paths"); | ||
| 46 | - // RegisterPath("/", HttpMethod::All, handler); | ||
| 47 | - throw std::runtime_error("not implemented yet"); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | 44 | void ExpressCpp::Use(handler_wn_t handler) { | |
| 51 | 45 | Console::Debug("using handler for all paths"); | |
| 52 | 46 | router_->Use(handler); | |
@@ -101,20 +95,6 @@ ExpressCpp& ExpressCpp::Listen(const uint16_t port, ready_fn_cb_error_code_t cal | |||
| 101 | 95 | return *this; | |
| 102 | 96 | } | |
| 103 | 97 | ||
| 104 | - void ExpressCpp::Use(StaticFileProviderPtr static_file_provider) { | ||
| 105 | - router_->Use([&](auto req, auto res, auto next) { static_file_provider->HandleRequests(req, res, next); }); | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - void ExpressCpp::Use(std::string_view path, StaticFileProviderPtr static_file_provider) { | ||
| 109 | - (void)path; | ||
| 110 | - (void)static_file_provider; | ||
| 111 | - throw std::runtime_error("not implemented yet"); | ||
| 112 | - // RegisterPath(path, HttpMethod::Get, [&](auto req, auto res) { | ||
| 113 | - // static_file_provider->UsePrefix(path); | ||
| 114 | - // static_file_provider->HandleRequests(req, res); | ||
| 115 | - // }); | ||
| 116 | - } | ||
| 117 | - | ||
| 118 | 98 | void ExpressCpp::Run() { | |
| 119 | 99 | std::unique_lock<std::mutex> lock(running_mtx); | |
| 120 | 100 | while (!finished_) { | |
@@ -140,16 +120,6 @@ RouterPtr ExpressCpp::GetRouter(std::string_view name) { | |||
| 140 | 120 | return r; | |
| 141 | 121 | } | |
| 142 | 122 | ||
| 143 | - StaticFileProviderPtr ExpressCpp::GetStaticFileProvider(const std::filesystem::path& path_to_root_folder) { | ||
| 144 | - if (!std::filesystem::exists(path_to_root_folder)) { | ||
| 145 | - throw std::runtime_error("path to root folder with static files does not exist"); | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - auto p = std::make_shared<StaticFileProvider>(path_to_root_folder); | ||
| 149 | - static_file_providers_.push_back(p); | ||
| 150 | - return p; | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | 123 | void ExpressCpp::HandleRequest(request_t req, response_t res, std::function<void()> callback) { | |
| 154 | 124 | assert(req != nullptr); | |
| 155 | 125 | assert(res != nullptr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #include "boost/algorithm/string.hpp" | |
| 7 | 7 | #include "boost/uuid/uuid_generators.hpp" | |
| 8 | 8 | #include "boost/uuid/uuid_io.hpp" | |
| 9 | + | ||
| 9 | 10 | #include "expresscpp/console.hpp" | |
| 10 | 11 | #include "expresscpp/impl/matcher.hpp" | |
| 11 | 12 | #include "expresscpp/impl/utils.hpp" | |
@@ -131,7 +132,6 @@ void Router::HandleRequest(std::shared_ptr<Request> req, std::shared_ptr<Respons | |||
| 131 | 132 | getHttpMethodName(req->getMethod()))); | |
| 132 | 133 | ||
| 133 | 134 | // find next matching layer | |
| 134 | - auto layerError = ""s; | ||
| 135 | 135 | req->idx = 0; | |
| 136 | 136 | Next(req, res); | |
| 137 | 137 | NextRouter next_handler(this, req, res); | |
@@ -168,7 +168,6 @@ std::shared_ptr<Route> Router::CreateRoute(const std::string_view registered_pat | |||
| 168 | 168 | auto r = std::make_shared<Route>(registered_path); | |
| 169 | 169 | ||
| 170 | 170 | // create layer and add it to the stack | |
| 171 | - | ||
| 172 | 171 | PathToRegExpOptions op{.sensitive = this->caseSensitive, .strict = true, .end = true}; | |
| 173 | 172 | std::shared_ptr<Layer> l = | |
| 174 | 173 | std::make_shared<Layer>(registered_path, op, parent_path_, [&](auto req, auto res, auto next) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,11 +5,13 @@ | |||
| 5 | 5 | ||
| 6 | 6 | #include "boost/uuid/uuid_generators.hpp" | |
| 7 | 7 | #include "boost/uuid/uuid_io.hpp" | |
| 8 | + #include "gtest/gtest.h" | ||
| 9 | + #include "nlohmann/json.hpp" | ||
| 10 | + | ||
| 8 | 11 | #include "expresscpp/console.hpp" | |
| 9 | 12 | #include "expresscpp/expresscpp.hpp" | |
| 10 | 13 | #include "expresscpp/fetch.hpp" | |
| 11 | - #include "gtest/gtest.h" | ||
| 12 | - #include "nlohmann/json.hpp" | ||
| 14 | + #include "expresscpp/middleware/serve_static_provider.hpp" | ||
| 13 | 15 | ||
| 14 | 16 | using namespace expresscpp; | |
| 15 | 17 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments