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

feat: reaneble static file provider · expresscpp/expresscpp@27e2529 · GitHub

Commit 27e2529

Browse files
committed
feat: reaneble static file provider
1 parent 23923ab commit 27e2529

16 files changed

Lines changed: 106 additions & 163 deletions

‎.gitlab-ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ deploy-latest-docker:
5959
cmake .. \
6060
-DEXPRESSCPP_ENABLE_COVERAGE=ON \
6161
-DEXPRESSCPP_BUILD_EXAMPLES=ON \
62+
-DEXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER=ON \
6263
-DEXPRESSCPP_BUILD_TESTS=ON
6364
- make -j2
6465
- |

‎.vscode/settings.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
},
103103
"cmake.configureSettings": {
104104
"EXPRESSCPP_BUILD_TESTS": true,
105-
"EXPRESSCPP_BUILD_EXAMPLES": true
106-
}
105+
"EXPRESSCPP_BUILD_EXAMPLES": true,
106+
"EXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER": true
107+
}
107108
}

‎CMakeLists.txt‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ if(MSVC)
6363
message(STATUS "using msvc")
6464
add_definitions(-D_WIN32_WINNT=0x600)
6565
add_definitions(-DBOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT)
66-
if (MSVC_VERSION GREATER_EQUAL "1900")
66+
if(MSVC_VERSION GREATER_EQUAL "1900")
6767
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")
7172
endif()
7273
endif()
7374
else()
@@ -157,6 +158,7 @@ else()
157158
endif()
158159

159160
if(EXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER)
161+
message(STATUS "building with static file provider")
160162
add_definitions(-DEXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER)
161163
endif()
162164

@@ -221,8 +223,7 @@ target_compile_options(
221223
${PROJECT_NAME}
222224
PRIVATE $<$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall>
223225
$<$<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>)
226227
if(CLANG_TIDY_EXE)
227228
set_target_properties(${PROJECT_NAME}
228229
PROPERTIES CXX_CLANG_TIDY
@@ -233,11 +234,11 @@ if(EXPRESSCPP_USE_STACKTRACE)
233234
message(STATUS "using boost stack trace")
234235
add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE)
235236
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>)
241242
target_link_libraries(${PROJECT_NAME}
242243
PUBLIC # for boost stackstrace
243244
${CMAKE_DL_LIBS})

‎build.sh‎

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

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
55
rm -rf _build
66
mkdir _build
77
cd _build
8-
cmake .. \
8+
cmake .. -GNinja \
99
-DEXPRESSCPP_BUILD_EXAMPLES=ON \
1010
-DEXPRESSCPP_BUILD_TESTS=ON
1111

12-
make -j4
12+
cmake --build . -j
1313

1414
# docker build -t registry.gitlab.com/expresscpp/expresscpp/ci_gcc8 -f docker/ci_gcc8/Dockerfile .
1515
# docker push registry.gitlab.com/expresscpp/expresscpp/ci_gcc8

‎example/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ add_example(simple_rest_router_server)
2727
add_example(error_handler)
2828

2929
if(EXPRESSCPP_ENABLE_STATIC_FILE_PROVIDER)
30-
add_example(simple_static_file_server)
30+
add_example(static_file_server)
3131
endif()
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
#include "expresscpp/expresscpp.hpp"
99

10-
int main() {
11-
std::cout << "Hello World!" << std::endl;
10+
using namespace expresscpp;
1211

13-
auto expresscpp = std::make_shared<ExpressCpp>();
12+
int main() {
13+
ExpressCpp expresscpp;
1414

1515
// get a folder to write to
16-
std::string doc_root = "/tmp/www";
16+
const std::string doc_root = "/tmp/www";
1717
std::filesystem::create_directory(doc_root);
1818

1919
// create a html index file
@@ -34,11 +34,21 @@ int main() {
3434
index_html_file.close();
3535

3636
// tell express to look for files in this directory
37-
expresscpp->Use(expresscpp->GetStaticFileProvider(doc_root));
37+
expresscpp.Use(expresscpp.GetStaticFileProvider(doc_root));
3838

3939
// start listening for requests and block until ctrl+C
4040
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();
4252

4353
return 0;
4454
}

‎include/expresscpp/expresscpp.hpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ class ExpressCpp {
8585
std::function<void(const std::error_code)> callback);
8686

8787
private:
88-
void RegisterPath(const std::string_view path, const HttpMethod method, express_handler_t handler,
89-
const bool is_router = false);
9088
void RegisterPath(const std::string_view path, const HttpMethod method, express_handler_wn_t handler);
9189
void Init();
9290

‎include/expresscpp/impl/session.hpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ExpressCpp;
2323
class Response;
2424
class Listener;
2525

26-
using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp>
2726
using SessionParser = http::request_parser<http::string_body>;
2827

2928
// Handles an HTTP server connection
@@ -32,11 +31,11 @@ class Session : public std::enable_shared_from_this<Session> {
3231

3332
public:
3433
// Take ownership of the stream
35-
Session(tcp::socket socket, ExpressCpp* express_cpp);
34+
Session(boost::asio::ip::tcp::socket socket, ExpressCpp* express_cpp);
3635

3736
~Session();
3837

39-
tcp::socket socket_;
38+
boost::asio::ip::tcp::socket socket_;
4039

4140
beast::flat_buffer buffer_{8192};
4241
std::shared_ptr<void> res_;

‎include/expresscpp/middleware/staticfileprovider.hpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#pragma once
22

33
#include <filesystem>
4-
#include <iostream>
4+
#include <string>
55

66
#include "expresscpp/types.hpp"
7+
78
namespace expresscpp {
89

910
class StaticFileProvider {
@@ -16,8 +17,9 @@ class StaticFileProvider {
1617

1718
private:
1819
std::filesystem::path path_to_root_folder_{"/tmp"};
19-
std::string_view doc_root{"/tmp"};
20+
// std::string_view doc_root{"/tmp"};
2021
};
2122

2223
typedef std::shared_ptr<StaticFileProvider> StaticFileProviderPtr;
24+
2325
} // namespace expresscpp

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL