main.cc 760 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // main.cc
  3. //
  4. // Copyright (c) 2024 Yuji Hirose. All rights reserved.
  5. // MIT License
  6. //
  7. #include <cstdio>
  8. #include <httplib.h>
  9. #include <iostream>
  10. using namespace httplib;
  11. using namespace std;
  12. auto error_html = R"(<html>
  13. <head><title>%d %s</title></head>
  14. <body>
  15. <center><h1>404 Not Found</h1></center>
  16. <hr><center>cpp-httplib/%s</center>
  17. </body>
  18. </html>
  19. )";
  20. int main(int argc, const char **argv) {
  21. Server svr;
  22. svr.set_error_handler([](const Request & /*req*/, Response &res) {
  23. char buf[BUFSIZ];
  24. snprintf(buf, sizeof(buf), error_html, res.status,
  25. status_message(res.status), CPPHTTPLIB_VERSION);
  26. res.set_content(buf, "text/html");
  27. });
  28. svr.set_mount_point("/", "./html");
  29. svr.listen("0.0.0.0", 80);
  30. return 0;
  31. }