add ubuntu support
This commit is contained in:
parent
41f0a38ec1
commit
0d0f2767b9
|
@ -4,6 +4,7 @@ pgsql
|
||||||
x64
|
x64
|
||||||
/WebApp/WebApp/log
|
/WebApp/WebApp/log
|
||||||
/config.json
|
/config.json
|
||||||
|
/build
|
||||||
|
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Build
|
||||||
|
|
||||||
|
*Refer to [readme](dependencies/README-Windows.md) for setting up the dependencies.*
|
||||||
|
|
||||||
|
Use VS2019 to open `WebApp/WebApp.sln`, which is a sample project. Remember to properly configure the database and `config.json` before you `Run` the project.
|
||||||
|
|
||||||
|
> `bserv` and `WebApp` should be built in `Debug` or `Release` (`x64`), NOT (`Win32`/`x86`).
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Build
|
||||||
|
|
||||||
|
*Refer to [readme](dependencies/README-ubuntu.md) for setting up the dependencies.*
|
||||||
|
|
||||||
|
shell:
|
||||||
|
```
|
||||||
|
mkdir build && cd build
|
||||||
|
cmake ..
|
||||||
|
cmake --build .
|
||||||
|
```
|
||||||
|
|
||||||
|
Assuming the shell is in `build`, you can run `WebApp` using:
|
||||||
|
```
|
||||||
|
cd WebApp/WebApp
|
||||||
|
./WebApp ../../../config.json
|
||||||
|
```
|
||||||
|
given that the database and `config.json` are properly configured.
|
||||||
|
|
||||||
|
> If some of the dynamically linked libraries are missing, try:
|
||||||
|
> ```
|
||||||
|
> sudo ldconfig
|
||||||
|
> ```
|
|
@ -0,0 +1,19 @@
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
project(bserv_project)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
16
README.md
16
README.md
|
@ -3,20 +3,14 @@
|
||||||
*A Boost Based C++ HTTP JSON Server.*
|
*A Boost Based C++ HTTP JSON Server.*
|
||||||
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
|
|
||||||
- VS2019
|
|
||||||
- CMake
|
|
||||||
- PostgreSQL
|
|
||||||
> *The database may not be installed locally. You should be able to connect to it.*
|
|
||||||
|
|
||||||
*Refer to [readme](dependencies/README.md) for setting up the dependencies.*
|
|
||||||
|
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
Use VS2019 to open `WebApp/WebApp.sln`, which is a sample project. [`config-example.json`](config-example.json) is a sample config file for `WebApp`'s startup parameters. **It should be renamed to `config.json` before you `Run` the project.**
|
> 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`.
|
||||||
|
- `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
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
add_executable(
|
||||||
|
WebApp
|
||||||
|
|
||||||
|
handlers.cpp
|
||||||
|
rendering.cpp
|
||||||
|
WebApp.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
WebApp PUBLIC
|
||||||
|
|
||||||
|
../../dependencies/inja/include
|
||||||
|
../../dependencies/inja/third_party/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
WebApp PUBLIC
|
||||||
|
|
||||||
|
bserv
|
||||||
|
)
|
||||||
|
|
|
@ -96,7 +96,7 @@ int main(int argc, char* argv[]) {
|
||||||
bserv::placeholders::_1),
|
bserv::placeholders::_1),
|
||||||
|
|
||||||
// serving html template files
|
// serving html template files
|
||||||
bserv::make_path("/", &index,
|
bserv::make_path("/", &index_page,
|
||||||
bserv::placeholders::session,
|
bserv::placeholders::session,
|
||||||
bserv::placeholders::response),
|
bserv::placeholders::response),
|
||||||
bserv::make_path("/form_login", &form_login,
|
bserv::make_path("/form_login", &form_login,
|
||||||
|
|
|
@ -280,7 +280,7 @@ std::nullopt_t index(
|
||||||
return render(response, template_path, context);
|
return render(response, template_path, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::nullopt_t index(
|
std::nullopt_t index_page(
|
||||||
std::shared_ptr<bserv::session_type> session_ptr,
|
std::shared_ptr<bserv::session_type> session_ptr,
|
||||||
bserv::response_type& response) {
|
bserv::response_type& response) {
|
||||||
boost::json::object context;
|
boost::json::object context;
|
||||||
|
|
|
@ -47,7 +47,7 @@ std::nullopt_t serve_static_files(
|
||||||
bserv::response_type& response,
|
bserv::response_type& response,
|
||||||
const std::string& path);
|
const std::string& path);
|
||||||
|
|
||||||
std::nullopt_t index(
|
std::nullopt_t index_page(
|
||||||
std::shared_ptr<bserv::session_type> session_ptr,
|
std::shared_ptr<bserv::session_type> session_ptr,
|
||||||
bserv::response_type& response);
|
bserv::response_type& response);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
add_library(
|
||||||
|
bserv
|
||||||
|
|
||||||
|
pch.cpp
|
||||||
|
bserv.cpp
|
||||||
|
client.cpp
|
||||||
|
database.cpp
|
||||||
|
session.cpp
|
||||||
|
utils.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
bserv PUBLIC
|
||||||
|
|
||||||
|
../../dependencies
|
||||||
|
../../dependencies/libpqxx/include
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
bserv PUBLIC
|
||||||
|
|
||||||
|
pthread
|
||||||
|
boost_thread
|
||||||
|
boost_context
|
||||||
|
boost_coroutine
|
||||||
|
boost_system
|
||||||
|
boost_filesystem
|
||||||
|
boost_log
|
||||||
|
boost_log_setup
|
||||||
|
boost_json
|
||||||
|
pqxx
|
||||||
|
pq
|
||||||
|
cryptopp
|
||||||
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef _COMMON_HPP
|
#ifndef _COMMON_HPP
|
||||||
#define _COMMON_HPP
|
#define _COMMON_HPP
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
#define _WIN32_WINNT 0x0601
|
#define _WIN32_WINNT 0x0601
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
@ -13,4 +15,4 @@
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "websocket.hpp"
|
#include "websocket.hpp"
|
||||||
|
|
||||||
#endif // _COMMON_HPP
|
#endif // _COMMON_HPP
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef _LOGGING_HPP
|
#ifndef _LOGGING_HPP
|
||||||
#define _LOGGING_HPP
|
#define _LOGGING_HPP
|
||||||
|
|
||||||
//#define BOOST_LOG_DYN_LINK
|
#if defined(__GNUC__)
|
||||||
|
#define BOOST_LOG_DYN_LINK
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/log/core.hpp>
|
#include <boost/log/core.hpp>
|
||||||
#include <boost/log/common.hpp>
|
#include <boost/log/common.hpp>
|
||||||
|
@ -54,4 +56,4 @@ namespace bserv {
|
||||||
|
|
||||||
} // bserv
|
} // bserv
|
||||||
|
|
||||||
#endif // _LOGGING_HPP
|
#endif // _LOGGING_HPP
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"port": 8080,
|
||||||
|
"thread-num": 2,
|
||||||
|
"conn-num": 4,
|
||||||
|
"conn-str": "postgresql://[username]:[password]@[url]:[port]/[db]",
|
||||||
|
"static_root": "../../../templates/statics",
|
||||||
|
"template_root": "../../../templates"
|
||||||
|
}
|
|
@ -1,6 +1,13 @@
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
|
|
||||||
|
To build the dependencies & the project itself, The following must be installed:
|
||||||
|
- Microsoft Visual Studio 2019 (VS2019)
|
||||||
|
- CMake
|
||||||
|
|
||||||
|
For each dependency, CMD is assumed to be in the directory of `dependencies`. So, the first command is always changing into the directory which contains the dependency.
|
||||||
|
|
||||||
|
|
||||||
## [Boost](https://www.boost.org/)
|
## [Boost](https://www.boost.org/)
|
||||||
|
|
||||||
CMD:
|
CMD:
|
||||||
|
@ -22,6 +29,8 @@ b2
|
||||||
|
|
||||||
# [PostgreSQL 14.0](https://www.postgresql.org/)
|
# [PostgreSQL 14.0](https://www.postgresql.org/)
|
||||||
|
|
||||||
|
*The database may not be installed locally. You should be able to connect to it.*
|
||||||
|
|
||||||
1. Use this [link](https://get.enterprisedb.com/postgresql/postgresql-14.0-1-windows-x64-binaries.zip) to download the binaries.
|
1. Use this [link](https://get.enterprisedb.com/postgresql/postgresql-14.0-1-windows-x64-binaries.zip) to download the binaries.
|
||||||
2. Unzip the zip archive here. It should be named `pgsql` and contains `bin`, `include` and `lib`.
|
2. Unzip the zip archive here. It should be named `pgsql` and contains `bin`, `include` and `lib`.
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Dependencies (Ubuntu)
|
||||||
|
|
||||||
|
|
||||||
|
To build the dependencies & the project itself, The following must be installed:
|
||||||
|
- g++
|
||||||
|
- make
|
||||||
|
- CMake
|
||||||
|
|
||||||
|
For each dependency, shell is assumed to be in the directory of `dependencies`. So, the first command is always changing into the directory which contains the dependency.
|
||||||
|
|
||||||
|
|
||||||
|
## [Boost](https://www.boost.org/)
|
||||||
|
shell:
|
||||||
|
```
|
||||||
|
cd boost
|
||||||
|
./bootstrap
|
||||||
|
./b2
|
||||||
|
sudo ./b2 install
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## [Crypto++](https://cryptopp.com/)
|
||||||
|
shell:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd cryptopp
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# [PostgreSQL](https://www.postgresql.org/)
|
||||||
|
**The database should be installed locally.**
|
||||||
|
|
||||||
|
|
||||||
|
# [Libpqxx](https://github.com/jtv/libpqxx)
|
||||||
|
shell:
|
||||||
|
```
|
||||||
|
cd libpqxx
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# [inja](https://github.com/pantor/inja)
|
||||||
|
|
||||||
|
*Nothing should be done...*
|
Loading…
Reference in New Issue