first commit
This commit is contained in:
31
backend.cpp
Normal file
31
backend.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user