From 07d638e70485bc82cb2b673c00878c8b8040de5e Mon Sep 17 00:00:00 2001 From: parovoz Date: Fri, 10 Oct 2025 22:01:22 +0400 Subject: [PATCH] init --- .gitea/workflows/build.yaml | 43 +++++++++++++++++++ .gitignore | 82 +++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 49 ++++++++++++++++++++++ server-example.sh.in | 25 +++++++++++ src/main.cpp | 32 +++++++++++++++ 5 files changed, 231 insertions(+) create mode 100644 .gitea/workflows/build.yaml create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 server-example.sh.in create mode 100644 src/main.cpp diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..57867c6 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -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 + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa3808c --- /dev/null +++ b/.gitignore @@ -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*/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0d2e960 --- /dev/null +++ b/CMakeLists.txt @@ -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 +) + diff --git a/server-example.sh.in b/server-example.sh.in new file mode 100644 index 0000000..8194f3b --- /dev/null +++ b/server-example.sh.in @@ -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 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..f04e8de --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +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(), "/say-my-name"); + + server.run(); + + return 0; +}