diff --git a/CMakeLists.txt b/CMakeLists.txt index 62777cc..62b1a5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,6 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -link_directories( - dependencies/cryptopp - dependencies/libpqxx/src/.libs -) - add_subdirectory(WebApp/bserv) add_subdirectory(WebApp/WebApp) diff --git a/README.md b/README.md index ba7d6db..a5efe55 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,55 @@ ## Quick Start -> To build the dependencies & the project, refer to [`BUILD-Windows.md`](BUILD-Windows.md) or [`BUILD-ubuntu.md`](BUILD-ubuntu.md) +> To build the dependencies & the project, refer to [`BUILD-Windows.md`](BUILD-Windows.md) or [`BUILD-ubuntu.md`](BUILD-ubuntu.md). - `WebApp/bserv` contains the source code for `bserv`. + + +### Hello, World! + +*This [example](examples/hello-world) shows how to use `bserv` to echo a json object `{"msg": "hello, world!"}` when requesting `localhost:8080/hello`.* + +`main.cpp`: +```C++ +#include +#include +boost::json::object hello() +{ + return {{"msg", "hello, world!"}}; +} +int main() +{ + bserv::server_config config; + // config.set_port(8080); + bserv::server{config, { + bserv::make_path("/hello", &hello) + }}; +} +``` + +`CMakeLists.txt`: +``` +cmake_minimum_required(VERSION 3.10) + +project(hello) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_subdirectory(path/to/WebApp/bserv bserv) +add_executable(main main.cpp) +target_link_libraries(main PUBLIC bserv) +``` + + +### Sample Project: `WebApp` + - `WebApp/WebApp` is a sample project. - [`config-Windows.json`](config-Windows.json) and [`config-ubuntu.json`](config-ubuntu.json) are two sample config file for `WebApp`'s startup parameters. **It should be configured and renamed to `config.json` before you start `WebApp`.** - To use `WebApp`, you should setup the database as well. -### Database +#### Database You can import the sample database: diff --git a/WebApp/bserv/CMakeLists.txt b/WebApp/bserv/CMakeLists.txt index b72d2f9..40a5e6f 100644 --- a/WebApp/bserv/CMakeLists.txt +++ b/WebApp/bserv/CMakeLists.txt @@ -29,8 +29,8 @@ target_link_libraries( boost_log boost_log_setup boost_json - pqxx + "${CMAKE_CURRENT_SOURCE_DIR}/../../dependencies/cryptopp/libcryptopp.a" + "${CMAKE_CURRENT_SOURCE_DIR}/../../dependencies/libpqxx/src/.libs/libpqxx.a" pq - cryptopp ) diff --git a/examples/hello-world/.gitignore b/examples/hello-world/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/examples/hello-world/.gitignore @@ -0,0 +1 @@ +/build diff --git a/examples/hello-world/CMakeLists.txt b/examples/hello-world/CMakeLists.txt new file mode 100644 index 0000000..4d28eab --- /dev/null +++ b/examples/hello-world/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.10) + +project(hello) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_subdirectory(../../WebApp/bserv bserv) +add_executable(main main.cpp) +target_link_libraries(main PUBLIC bserv) diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp new file mode 100644 index 0000000..369b010 --- /dev/null +++ b/examples/hello-world/main.cpp @@ -0,0 +1,14 @@ +#include +#include +boost::json::object hello() +{ + return {{"msg", "hello, world!"}}; +} +int main() +{ + bserv::server_config config; + // config.set_port(8080); + bserv::server{config, { + bserv::make_path("/hello", &hello) + }}; +}