From ff7ddd4b0297e545f12f8182ef92c4ac8d103afb Mon Sep 17 00:00:00 2001 From: consoir <consoir@itc.rwth-aachen.de> Date: Thu, 10 Oct 2024 14:34:15 +0200 Subject: [PATCH] update --- Makefile | 43 +++++++++++++++---------------------------- src/main.cpp | 16 +++++++++------- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 9d39059..ec1bbb0 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,27 @@ +# Makefile + .PHONY: all clean CXX = g++ -CXXFLAGS = -std=c++11 -O2 -Icrow/include -LDFLAGS = -lpthread # Add pthread library +CXXFLAGS = -std=c++17 -O2 -Icrow/include -I$(BOOST_INCLUDE_DIR) +LDFLAGS = -lpthread -lboost_system -lboost_thread TARGET = build/webservice SRC = src/main.cpp -# Function to truncate a string to the first 10 characters and add "..." if longer -define TRUNCATE -$(shell \ - str="$(1)"; \ - len=$$(echo -n "$$str" | wc -c); \ - if [ $$len -gt 20 ]; then \ - short=$$(echo "$$str" | cut -c1-20); \ - echo "$$short..."; \ - else \ - echo "$$str"; \ - fi \ -) -endef - -# Check if INCLUDE_DIR is set and valid -ifdef INCLUDE_DIR - TRUNC_INCLUDE_DIR := $(call TRUNCATE,$(INCLUDE_DIR)) - $(info INCLUDE_DIR is set to "$(TRUNC_INCLUDE_DIR)") - ifeq ($(shell [ -d "$(INCLUDE_DIR)" ] && echo yes || echo no),yes) - $(info Directory "$(TRUNC_INCLUDE_DIR)" exists. Adding to CXXFLAGS.) - CXXFLAGS += -I"$(INCLUDE_DIR)" - else - $(error Error: Directory "$(TRUNC_INCLUDE_DIR)" does not exist) - endif -else - $(info INCLUDE_DIR is not set. Skipping additional include directories.) +# Ensure BOOST_INCLUDE_DIR is set and valid +ifndef BOOST_INCLUDE_DIR + $(error BOOST_INCLUDE_DIR is not set. Please set it to the path of your Boost include directory.) +endif + +# Check if BOOST_INCLUDE_DIR exists +ifeq ($(wildcard $(BOOST_INCLUDE_DIR)),) + $(error BOOST_INCLUDE_DIR "$(BOOST_INCLUDE_DIR)" does not exist. Please provide a valid path.) endif +# Create build directory if it doesn't exist +$(shell mkdir -p build) + $(TARGET): $(SRC) @echo "Compiling the project with CXXFLAGS: $(CXXFLAGS)" $(CXX) $(CXXFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS) diff --git a/src/main.cpp b/src/main.cpp index 56021d0..1a518c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,13 @@ -#include "crow.h" +#include "crow.h" #include <cstdlib> -#include <sstream> +#include <sstream> +#include <fstream> int main() { - crow::SimpleApp app; - - CROW_ROUTE(app, "/execute").methods("POST"_method)([](const crow::request& req) { + crow::SimpleApp app; + CROW_ROUTE(app, "/execute").methods(crow::HTTPMethod::Post) + ([](const crow::request& req, crow::response& res) { std::string command = req.body; std::string full_command = command + " 2>&1 | tee output.txt"; @@ -18,10 +19,11 @@ int main() { output_buffer << output_file.rdbuf(); std::string output = output_buffer.str(); - return "Done"; + res.write("Done"); + res.end(); }); app.port(10001).multithreaded().run(); return 0; -} +} \ No newline at end of file -- GitLab