mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Add docker related files
This commit is contained in:
parent
048edec9ed
commit
52a18c78a5
3 changed files with 71 additions and 0 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
FROM ubuntu AS builder
|
||||
WORKDIR /app
|
||||
COPY httplib.h .
|
||||
COPY docker/main.cc .
|
||||
RUN apt update && apt install g++ -y
|
||||
RUN g++ -std=c++14 -static -o server -O3 -I. -DCPPHTTPLIB_USE_POLL main.cc
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /app/server /server
|
||||
COPY docker/index.html /html/index.html
|
||||
CMD ["/server"]
|
21
docker/index.html
Normal file
21
docker/index.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to cpp-httplib!</title>
|
||||
<style>
|
||||
html { color-scheme: light dark; }
|
||||
body { width: 35em; margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to cpp-httplib!</h1>
|
||||
<p>If you see this page, the cpp-httplib web server is successfully installed and
|
||||
working. Further configuration is required.</p>
|
||||
|
||||
<p>For online documentation and support please refer to
|
||||
<a href="https://github.com/yhirose/cpp-httplib">github.com/yhirose/cpp-httplib</a>.<br/>
|
||||
|
||||
<p><em>Thank you for using cpp-httplib.</em></p>
|
||||
</body>
|
||||
</html>
|
39
docker/main.cc
Normal file
39
docker/main.cc
Normal file
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// main.cc
|
||||
//
|
||||
// Copyright (c) 2024 Yuji Hirose. All rights reserved.
|
||||
// MIT License
|
||||
//
|
||||
|
||||
#include <cstdio>
|
||||
#include <httplib.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace httplib;
|
||||
using namespace std;
|
||||
|
||||
auto error_html = R"(<html>
|
||||
<head><title>%d %s</title></head>
|
||||
<body>
|
||||
<center><h1>404 Not Found</h1></center>
|
||||
<hr><center>cpp-httplib/%s</center>
|
||||
</body>
|
||||
</html>
|
||||
)";
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
Server svr;
|
||||
|
||||
svr.set_error_handler([](const Request & /*req*/, Response &res) {
|
||||
char buf[BUFSIZ];
|
||||
snprintf(buf, sizeof(buf), error_html, res.status,
|
||||
status_message(res.status), CPPHTTPLIB_VERSION);
|
||||
res.set_content(buf, "text/html");
|
||||
});
|
||||
|
||||
svr.set_mount_point("/", "./html");
|
||||
|
||||
svr.listen("0.0.0.0", 80);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue