StaticWebPageController.cpp 598 B

12345678910111213141516171819202122232425
  1. //
  2. // Created by xcbosa on 2023/1/28.
  3. //
  4. #include "../processor/processor.h"
  5. #include "../utils/utils.h"
  6. #include <sys/stat.h>
  7. using namespace std;
  8. using namespace xc::processor;
  9. namespace xc::controller {
  10. static ContentGenerator staticWebPageController([] (auto p) {
  11. if (p.getMethod() != "GET") { return false; }
  12. struct stat buffer;
  13. string filePath = "html/" + p.getURL();
  14. return stat(filePath.c_str(), &buffer) == 0;
  15. }, [] (auto p) {
  16. string filePath = "html/" + p.getURL();
  17. return new BinaryResponseData(200, filePath, "");
  18. });
  19. }