FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor: clean up more old code · expresscpp/expresscpp@eb0e4db · GitHub

Commit eb0e4db

Browse files
committed
refactor: clean up more old code
1 parent 75039a1 commit eb0e4db

8 files changed

Lines changed: 27 additions & 51 deletions

File tree

‎build.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/bin/bash
22

3+
4+
export CC=/usr/bin/clang-8
5+
export CXX=/usr/bin/clang++-8
36
rm -rf _build
47
mkdir _build
58
cd _build
69
cmake .. -GNinja \
710
-DEXPRESSCPP_BUILD_EXAMPLES=ON \
811
-DEXPRESSCPP_BUILD_TESTS=ON \
912
-DEXPRESSCPP_USE_CONAN_DEPENDENCIES=ON
13+
-DEXPRESSCPP_RUN_CLANG_TIDY=ON
1014

1115
cmake --build . -j
1216

‎example/serve_static.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#include "boost/uuid/uuid_generators.hpp"
1111
#include "boost/uuid/uuid_io.hpp"
12+
1213
#include "expresscpp/console.hpp"
1314
#include "expresscpp/expresscpp.hpp"
15+
#include "expresscpp/middleware/serve_static_provider.hpp"
1416

1517
using namespace expresscpp;
1618

@@ -57,7 +59,7 @@ int main() {
5759
assert(std::filesystem::exists(path_to_doc));
5860
}
5961

60-
auto p = expresscpp.GetStaticFileProvider(doc_root);
62+
StaticFileProvider p(doc_root);
6163

6264
expresscpp.Use(p);
6365
const uint16_t port = 8081u;

‎example/simple_rest_router_server.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using namespace expresscpp;
1010

11-
void LoggerMiddleware(request_t req, response_t /*res*/) {
11+
void LoggerMiddleware(request_t req, response_t /*res*/, next_t /*next*/) {
1212
std::cout << "LOGGER: time: " << req->getTimeStamp() << ", path: "
1313
<< "\"" << req->getPath() << "\""
1414
<< ", method: "

‎include/expresscpp/expresscpp.hpp‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "expresscpp/route.hpp"
1515
#include "expresscpp/router.hpp"
1616
#include "expresscpp/types.hpp"
17-
#include "expresscpp/middleware/serve_static_provider.hpp"
1817

1918
namespace expresscpp {
2019

@@ -67,8 +66,6 @@ class ExpressCpp {
6766

6867
void Error(express_handler_wecn_t handler);
6968

70-
void Use(handler_t handler);
71-
7269
/*!
7370
* Proxy `Router#Use()` to add middleware to the app router.
7471
* See Router#use() documentation for details.
@@ -80,14 +77,12 @@ class ExpressCpp {
8077
void Use(std::string_view path, handler_t handler);
8178
void Use(std::string_view path, handler_wn_t handler);
8279
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);
8580

8681
auto GetBaseRouter();
8782

8883
std::shared_ptr<Route> CreateRoute(const std::string_view);
8984

90-
//! called to start listening on port @ref port_
85+
//! called to start listening on port
9186
ExpressCpp& Listen(const uint16_t port, ready_fn_cb_error_code_t callback);
9287

9388
void Run();
@@ -96,8 +91,6 @@ class ExpressCpp {
9691
RouterPtr GetRouter();
9792
RouterPtr GetRouter(std::string_view name);
9893

99-
StaticFileProviderPtr GetStaticFileProvider(const std::filesystem::path& path_to_root_folder);
100-
10194
std::vector<RoutingStack> Stack() const;
10295

10396
/**
@@ -112,11 +105,9 @@ class ExpressCpp {
112105
std::condition_variable running_cv;
113106
bool finished_{false};
114107
std::unique_ptr<Router> router_;
115-
std::vector<StaticFileProviderPtr> static_file_providers_;
116108
std::shared_ptr<Listener> listener_;
117109
std::vector<Route> routes_;
118110
std::size_t threads_{4u};
119-
std::uint16_t port_;
120111
bool error_handler_registered_{false};
121112
express_handler_wecn_t error_handler_;
122113
bool listening_{false};

‎include/expresscpp/router.hpp‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66

77
#include "boost/uuid/uuid.hpp"
8+
89
#include "expresscpp/layer.hpp"
910
#include "expresscpp/request.hpp"
1011
#include "expresscpp/response.hpp"
@@ -33,6 +34,7 @@ class Router {
3334
*/
3435
void Use(std::string_view path, handler_wn_t handler);
3536
void Use(handler_wn_t handler);
37+
3638
void Get(std::string_view path, handler_wn_t handler);
3739
void Post(std::string_view path, handler_wn_t handler);
3840
void Delete(std::string_view path, handler_wn_t handler);
@@ -63,11 +65,6 @@ class Router {
6365
*/
6466
std::shared_ptr<Route> CreateRoute(const std::string_view registered_path);
6567

66-
std::vector<Route> routes_;
67-
68-
boost::uuids::uuid uuid_;
69-
std::chrono::system_clock::time_point timestamp_;
70-
7168
std::string_view GetName() const;
7269

7370
std::vector<std::shared_ptr<Layer>> stack() const;
@@ -99,8 +96,19 @@ class Router {
9996
*/
10097
bool strict{false};
10198

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
102108
std::string_view name_{"unknown"};
109+
103110
std::vector<std::shared_ptr<Layer>> stack_;
111+
104112
std::string parent_path_;
105113
};
106114

‎src/expresscpp.cpp‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ std::shared_ptr<Route> ExpressCpp::CreateRoute(const std::string_view registered
4141
return router_->CreateRoute(registered_path);
4242
}
4343

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-
5044
void ExpressCpp::Use(handler_wn_t handler) {
5145
Console::Debug("using handler for all paths");
5246
router_->Use(handler);
@@ -101,20 +95,6 @@ ExpressCpp& ExpressCpp::Listen(const uint16_t port, ready_fn_cb_error_code_t cal
10195
return *this;
10296
}
10397

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-
11898
void ExpressCpp::Run() {
11999
std::unique_lock<std::mutex> lock(running_mtx);
120100
while (!finished_) {
@@ -140,16 +120,6 @@ RouterPtr ExpressCpp::GetRouter(std::string_view name) {
140120
return r;
141121
}
142122

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-
153123
void ExpressCpp::HandleRequest(request_t req, response_t res, std::function<void()> callback) {
154124
assert(req != nullptr);
155125
assert(res != nullptr);

‎src/router.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "boost/algorithm/string.hpp"
77
#include "boost/uuid/uuid_generators.hpp"
88
#include "boost/uuid/uuid_io.hpp"
9+
910
#include "expresscpp/console.hpp"
1011
#include "expresscpp/impl/matcher.hpp"
1112
#include "expresscpp/impl/utils.hpp"
@@ -131,7 +132,6 @@ void Router::HandleRequest(std::shared_ptr<Request> req, std::shared_ptr<Respons
131132
getHttpMethodName(req->getMethod())));
132133

133134
// find next matching layer
134-
auto layerError = ""s;
135135
req->idx = 0;
136136
Next(req, res);
137137
NextRouter next_handler(this, req, res);
@@ -168,7 +168,6 @@ std::shared_ptr<Route> Router::CreateRoute(const std::string_view registered_pat
168168
auto r = std::make_shared<Route>(registered_path);
169169

170170
// create layer and add it to the stack
171-
172171
PathToRegExpOptions op{.sensitive = this->caseSensitive, .strict = true, .end = true};
173172
std::shared_ptr<Layer> l =
174173
std::make_shared<Layer>(registered_path, op, parent_path_, [&](auto req, auto res, auto next) {

‎test/static_file_middleware.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
#include "boost/uuid/uuid_generators.hpp"
77
#include "boost/uuid/uuid_io.hpp"
8+
#include "gtest/gtest.h"
9+
#include "nlohmann/json.hpp"
10+
811
#include "expresscpp/console.hpp"
912
#include "expresscpp/expresscpp.hpp"
1013
#include "expresscpp/fetch.hpp"
11-
#include "gtest/gtest.h"
12-
#include "nlohmann/json.hpp"
14+
#include "expresscpp/middleware/serve_static_provider.hpp"
1315

1416
using namespace expresscpp;
1517

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL