// Copyright Epic Games, Inc. All Rights Reserved. #include "frontend.h" #include #include namespace zen { namespace html { constexpr std::string_view Index = R"(
__________                  _________  __                           
\____    /  ____    ____   /   _____/_/  |_   ____  _______   ____  
  /     / _/ __ \  /    \  \_____  \ \   __\ /  _ \ \_  __ \_/ __ \ 
 /     /_ \  ___/ |   |  \ /        \ |  |  (  <_> ) |  | \/\  ___/ 
/_______ \ \___  >|___|  //_______  / |__|   \____/  |__|    \___  >
        \/     \/      \/         \/                             \/ 
				
			
Z$:

		
)"; } // namespace html HttpFrontendService::HttpFrontendService(std::filesystem::path Directory) : m_Directory(Directory) { } HttpFrontendService::~HttpFrontendService() { } const char* HttpFrontendService::BaseUri() const { return "/dashboard"; // in order to use the root path we need to remove HttpAddUrlToUrlGroup in HttpSys.cpp } void HttpFrontendService::HandleRequest(zen::HttpServerRequest& Request) { using namespace std::literals; if (m_Directory.empty()) { Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kHTML, html::Index); } else { std::string_view Uri = Request.RelativeUri(); std::filesystem::path RelPath{Uri.empty() ? "index.html" : Uri}; std::filesystem::path AbsPath = m_Directory / RelPath; FileContents File = ReadFile(AbsPath); if (!File.ErrorCode) { // TODO: Map file extension to MIME type Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kHTML, File.Data[0]); } else { return Request.WriteResponse(HttpResponseCode::NotFound, HttpContentType::kText, "Ooops!"sv); } } } } // namespace zen