Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
container_webservice_crow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon Consoir
container_webservice_crow
Commits
ff7ddd4b
Commit
ff7ddd4b
authored
9 months ago
by
Simon Consoir
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
a923cb22
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile
+15
-28
15 additions, 28 deletions
Makefile
src/main.cpp
+9
-7
9 additions, 7 deletions
src/main.cpp
with
24 additions
and
35 deletions
Makefile
+
15
−
28
View file @
ff7ddd4b
# Makefile
.PHONY
:
all clean
CXX
=
g++
CXXFLAGS
=
-std
=
c++1
1
-O2
-Icrow
/include
LDFLAGS
=
-lpthread
# Add pthread library
CXXFLAGS
=
-std
=
c++1
7
-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
)
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
9
−
7
View file @
ff7ddd4b
#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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment