Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding example 'webserver reverse proxy' #2035

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/webserver_reverse_proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
##
## directory
##
/bin
/build
/logs
/public


##
## extension
##
*.exe
*.out
*.app


##
## file
##
/.vscode/settings.json
/.vscode/launch.json
36 changes: 36 additions & 0 deletions examples/webserver_reverse_proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.15)
project(webserver_reverse_proxy_example)

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
if(HAS_ANY AND HAS_STRING_VIEW)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(Drogon CONFIG REQUIRED)

if(CMAKE_CXX_STANDARD LESS 17)
#With C++14, use boost to support any and string_view
message(STATUS "use c++14")
find_package(Boost 1.61.0 REQUIRED)
target_include_directories(simple_reverse_proxy PRIVATE ${Boost_INCLUDE_DIRS})
else()
message(STATUS "use c++17")
endif()

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

add_subdirectory(src/webserver/drogon_server)
add_subdirectory(src/backend/backend_api)
add_subdirectory(src/backend/backend_www)
71 changes: 71 additions & 0 deletions examples/webserver_reverse_proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# drogon framework example: webserver reverse proxy

__NOTE:__

```
this example show how to use drogon as webserver and using reverse proxy
```

<br>

## steps:

- add these:
```txt
127.0.0.1 localhost.com
127.0.0.1 api.localhost.com
127.0.0.1 admin.localhost.com
127.0.0.1 www.localhost.com
```

to

- __linux debian__ base location:

- `/etc/hosts`:

- __windows__ base location:

- `C:\Windows\System32\drivers\etc\hosts`:

---

- make it sure drogon config is already installed on your machine environment

- build this project, *you can use build-debug-linux.sh on linux environment*

- launch:
- terminal:
- go to _*./bin*_ directory and run each of these:
- `./drogon_server`
- `./backend_api`
- `./backend_www`

- open your browser:
- go to:
- `http://www.localhost.com:9999`:
- this will redirect to `http://localhost.com:9999`

- `http://localhost.com:9999`:
- will show example message and which port is called

- `http://api.localhost.com:9999`:
- will show json message from which port

- `http://api.localhost.com:9999/test`:
- will show json message from `/test` endpoint/path and show which port is called

<br>

---

## preview result example

- [preview result example 1](https://raw.githubusercontent.com/prothegee/prothegee/main/previews/_preview-example-drogon_server-1.png)
- [preview result example 2](https://raw.githubusercontent.com/prothegee/prothegee/main/previews/_preview-example-drogon_server-2.png)

<br>

---

###### end of readme
10 changes: 10 additions & 0 deletions examples/webserver_reverse_proxy/build-debug-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mkdir -p bin;
mkdir -p build;

mkdir -p logs/access;
mkdir -p logs/info;

mkdir -p public;

cmake -B build -DCMAKE_BUILD_TYPE=Debug;
cmake --build build --config Debug;
130 changes: 130 additions & 0 deletions examples/webserver_reverse_proxy/config.backend_api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"custom_config": {
"_": "don't use me"
},
"listeners": [
{
"address": "0.0.0.0",
"port": 9104,
"https": false
},
{
"address": "0.0.0.0",
"port": 9105,
"https": false
},
{
"address": "0.0.0.0",
"port": 9106,
"https": false
}
],
"mime": {
"text/markdown": "md",
"text/gemini": [
"gmi", "gemini"
],
"text/css": [
"css", "css.map"
],
"text/javascript": [
"js", "mjs", "js.map", "framework.js", "loader.js",
"audio.worklet.js",
"data", "pck",
"wasm", "side.wasm",
"worker.js"
]
},
"app": {
"number_of_threads": 2,
"document_root": "../public",
"enable_session": false,
"session_timeout": 604800,
"session_same_site" : "Strict",
"session_cookie_key": "_backend_api-session-id",
"max_connections": 262144,
"max_connections_per_ip": 0,
"client_max_body_size": "5M",
"client_max_memory_body_size": "5M",
"client_max_websocket_message_size": "5M",
"log": {
"use_spdlog": false,
"log_path": "../logs/info",
"logfile_base_name": "backend_api.info",
"log_size_limit": 100000000,
"max_files": 30,
"log_level": "INFO"
},
"run_as_daemon": false,
"relaunch_on_error": false,
"upload_path": "uploads",
"use_sendfile": true,
"use_gzip": true,
"use_brotli": true,
"static_files_cache_time": 480,
"idle_connection_timeout": 600,
"enable_server_header": true,
"server_header_field": "Drogon Framework",
"enable_date_header": false,
"keepalive_requests": 0,
"br_static": true,
"reuse_port": false,
"file_types": [
"gif",
"png",
"jpg",
"map",
"js",
"framework.js",
"loader.js",
"bundle.js",
"min.js",
"js.map",
"js.flow",
"module.js",
"cjs",
"mjs",
"css",
"css.map",
"min.css",
"min.css.map",
"rtl.css.map",
"rtl.min.css.map",
"scss",
"html",
"ico",
"swf",
"svg",
"xap",
"apk",
"cur",
"xml",
"ttf",
"woff",
"woff2",
"text",
"txt",
"json",
"audio.worklet.js",
"data",
"pck",
"wasm",
"side.wasm",
"worker.js"
]
},
"plugins": [
{
"name": "drogon::plugin::AccessLogger",
"dependencies": [],
"config": {
"log_path": "../logs/access",
"log_format": "$request_date $method $url [$body_bytes_received] ($remote_addr - $local_addr) $status $body_bytes_sent $processing_time",
"log_file": "backend_api.access.log",
"log_size_limit": 100000000,
"use_local_time": true,
"log_index": 0
}
}
]
}
Loading
Loading