commit bd66a42b95340499aa4423341ab4df8418f86121 Author: parovoz Date: Fri Oct 10 22:01:22 2025 +0400 init diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..6c05242 --- /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 test-server || echo service was not started + + - name: clear old installation + run: xargs rm < ~/build/test-server/install_manifest.txt || echo previous installation not found + + - name: clear old builddir + run: rm -rf ~/build/test-server || echo previous installation not found + + - name: update submodule + run: git submodule update --init --recursive + + - name: Configure CMake + run: cmake -B ~/build/test-server -DCMAKE_INSTALL_PREFIX=~/.local + + - name: Build + run: cmake --build ~/build/test-server + + - name: install + run: make -C ~/build/test-server install + + - name: Start server + run: ~/start.sh test-server + 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..96c5967 --- /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; +}