Skip to content
Snippets Groups Projects
Commit ff7ddd4b authored by Simon Consoir's avatar Simon Consoir
Browse files

update

parent a923cb22
No related branches found
No related tags found
No related merge requests found
# 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)
# 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
else
$(info INCLUDE_DIR is not set. Skipping additional include directories.)
# 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)
......
#include "crow.h"
#include <cstdlib>
#include <sstream>
#include <fstream>
int main() {
crow::SimpleApp app;
CROW_ROUTE(app, "/execute").methods("POST"_method)([](const crow::request& req) {
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,7 +19,8 @@ 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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment