Files
web_tool/backend.cpp
2025-10-11 17:15:21 +02:00

32 lines
701 B
C++

#include "crow.h"
#include <string>
#include <iostream>
int main() {
crow::SimpleApp app;
CROW_ROUTE(app, "/")([](){
auto page = crow::mustache::load_text("index.html");
return page;
});
CROW_ROUTE(app, "/button").methods("POST"_method)([](const crow::request& req) {
auto x = crow::json::load(req.body);
if (!x) {
return crow::response(400, "invalid JSON");
}
std::string name = x["name"].s();
name.erase(std::remove_if(name.begin(), name.end(), ::isspace), name.end());
std::cout << name << std::endl;
return crow::response(200, name);
});
app.port(18080).multithreaded().run();
}