This commit is contained in:
43
.gitea/workflows/build.yaml
Normal file
43
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,43 @@
|
||||
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
|
||||
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
|
||||
name: CMake on a single platform
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: archlinux
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Stop previous server if running
|
||||
run: ~/stop.sh server-example || echo service was not started
|
||||
|
||||
- name: clear old installation
|
||||
run: xargs rm < ~/build/server-example/install_manifest.txt || echo previous installation not found
|
||||
|
||||
- name: clear old builddir
|
||||
run: rm -rf ~/build/server-example || echo previous installation not found
|
||||
|
||||
- name: update submodule
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Configure CMake
|
||||
run: cmake -B ~/build/server-example -DCMAKE_INSTALL_PREFIX=~/.local
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ~/build/server-example
|
||||
|
||||
- name: install
|
||||
run: make -C ~/build/server-example install
|
||||
|
||||
- name: Start server
|
||||
run: ~/start.sh server-example
|
||||
|
82
.gitignore
vendored
Normal file
82
.gitignore
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
*.qbs.user*
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
# Directories with generated files
|
||||
.moc/
|
||||
.obj/
|
||||
.pch/
|
||||
.rcc/
|
||||
.uic/
|
||||
/build*/
|
49
CMakeLists.txt
Normal file
49
CMakeLists.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(server-example LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
find_package(Wt REQUIRED
|
||||
Wt
|
||||
HTTP
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
include_directories(
|
||||
"src"
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
Wt::Wt
|
||||
Wt::HTTP
|
||||
)
|
||||
|
||||
|
||||
configure_file(
|
||||
${PROJECT_NAME}.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wt
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wt
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
PERMISSIONS
|
||||
OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
|
25
server-example.sh.in
Normal file
25
server-example.sh.in
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
pid=''
|
||||
run=true
|
||||
|
||||
start() {
|
||||
@CMAKE_INSTALL_FULL_BINDIR@/@PROJECT_NAME@ \
|
||||
--docroot='/var/empty;/favicon.ico,/resources,/style,/node_modules' \
|
||||
--http-address 0.0.0.0 --http-port 8087 \
|
||||
--config /etc/wt/wt_config.xml \
|
||||
--resources-dir /usr/share/Wt/resources &> >(logger --tag @PROJECT_NAME@) & pid="$!"
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
run=false
|
||||
(( $pid )) && kill "$pid"
|
||||
}
|
||||
|
||||
trap shutdown EXIT
|
||||
|
||||
start
|
||||
while $run
|
||||
do
|
||||
wait "$pid" || { logger --tag @PROJECT_NAME@ -p 3 "restarting server after error"; start; }
|
||||
done
|
32
src/main.cpp
Normal file
32
src/main.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <Wt/WServer.h>
|
||||
#include <Wt/WResource.h>
|
||||
#include <Wt/Http/Request.h>
|
||||
#include <Wt/Http/Response.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Wt;
|
||||
|
||||
class TestResource : public WResource {
|
||||
public:
|
||||
void handleRequest(const Http::Request& request, Http::Response& response) override {
|
||||
if ( const string* name = request.getParameter("name") ) {
|
||||
response.out() << ( *name == string{"Heisenberg"}
|
||||
? "You god damn right."
|
||||
: "nope." )
|
||||
<< endl;
|
||||
} else {
|
||||
response.setStatus(400);
|
||||
response.out() << "say. my. name." << endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
WServer server{argc, argv};
|
||||
|
||||
server.addResource(make_shared<TestResource>(), "/say-my-name");
|
||||
|
||||
server.run();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user