webuiconf.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Created by xcbosa on 2023/1/28.
  3. //
  4. #pragma once
  5. #include <vector>
  6. #include <map>
  7. #include "utils/utils.h"
  8. using namespace std;
  9. using namespace xc::utils;
  10. namespace xc::conf {
  11. const int clientSocketTimeoutSeconds = 3;
  12. const int taskProcessTimeoutSeconds = 1;
  13. const int mtu = 1536;
  14. const bool enableStaticAssetsController = false;
  15. const map<string, string> fileExtensionToMimeTypes = {
  16. { ".html", "text/html" },
  17. { ".htm", "text/html" },
  18. { ".js", "text/javascript" },
  19. { ".ts", "text/typescript" },
  20. { ".xcnb", "text/xc-notebook" },
  21. { ".ccdproj", "application/c-code-develop-project" },
  22. { ".png", "image/png" },
  23. { ".jpg", "image/jpeg" },
  24. { ".jpeg", "image/jpeg" },
  25. { ".tiff", "image/tiff" },
  26. { ".css", "text/css" },
  27. { ".less", "text/css" },
  28. { ".scss", "text/css" },
  29. { ".svg", "image/svg+xml" },
  30. { ".ttf", "application/x-font-ttf" },
  31. { ".ttc", "application/x-font-ttf" },
  32. { ".woff", "application/x-font-woff" },
  33. { ".woff2", "application/x-font-woff" },
  34. { "default", "application/octet-stream" },
  35. };
  36. const vector<string> defaultFiles = {
  37. "index.html",
  38. "index.htm"
  39. };
  40. const IncompleteFileResponseData errorPage(FileResponseData(500, "html/error.html", "text/html"));
  41. const auto errorPage400 = errorPage.applyReplacements(400, {
  42. Replacement("errorMessage", "请求格式错误,无法解析请求"),
  43. Replacement("errorCode", "400")
  44. });
  45. const auto errorPage404 = errorPage.applyReplacements(404, {
  46. Replacement("errorMessage", "不存在指定的资源"),
  47. Replacement("errorCode", "404")
  48. });
  49. const auto errorPage500 = errorPage.applyReplacements(500, {
  50. Replacement("errorMessage", "服务器内部错误,可能是服务器访问量过大,请稍后重试"),
  51. Replacement("errorCode", "500")
  52. });
  53. const auto errorPageTimeout = errorPage.applyReplacements(550, {
  54. Replacement("errorMessage", "服务器任务处理已超时,可能服务器访问量过大,请稍后重试"),
  55. Replacement("errorCode", "550")
  56. });
  57. }