aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/frontend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/frontend/frontend.cpp')
-rw-r--r--src/zenserver/frontend/frontend.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/zenserver/frontend/frontend.cpp b/src/zenserver/frontend/frontend.cpp
index 579a65c5a..697cc014e 100644
--- a/src/zenserver/frontend/frontend.cpp
+++ b/src/zenserver/frontend/frontend.cpp
@@ -68,6 +68,14 @@ HttpFrontendService::HttpFrontendService(std::filesystem::path Directory, HttpSt
{
m_Directory = HtmlDir;
}
+
+ // Map data/ requests to the project docs/ directory in dev mode
+ std::filesystem::path DocsDir = ParentPath / "docs";
+ if (IsDir(DocsDir, ErrorCode))
+ {
+ m_DocsDirectory = DocsDir;
+ }
+
break;
}
Path = ParentPath;
@@ -145,6 +153,18 @@ HttpFrontendService::HandleRequest(zen::HttpServerRequest& Request)
const std::string_view DotExt = Uri.substr(DotIndex + 1);
ContentType = ParseContentType(DotExt);
+
+ // Extensions used only for static file serving — not in the global
+ // ParseContentType table because that table also drives URI extension
+ // stripping for content negotiation, and we don't want /api/foo.txt to
+ // have its extension removed.
+ if (ContentType == HttpContentType::kUnknownContentType)
+ {
+ if (DotExt == "txt" || DotExt == "md")
+ {
+ ContentType = HttpContentType::kText;
+ }
+ }
}
if (ContentType == HttpContentType::kUnknownContentType)
@@ -154,6 +174,21 @@ HttpFrontendService::HandleRequest(zen::HttpServerRequest& Request)
auto WriteResponseForUri = [this,
&Request](std::string_view InUri, HttpResponseCode ResponseCode, HttpContentType ContentType) -> bool {
+ // In dev mode, map data/ requests to the project docs/ directory
+ constexpr std::string_view DataPrefix = "data/";
+ if (!m_DocsDirectory.empty() && InUri.starts_with(DataPrefix))
+ {
+ std::string_view DocsRelative = InUri.substr(DataPrefix.size());
+ auto FullPath = m_DocsDirectory / std::filesystem::path(DocsRelative).make_preferred();
+ FileContents File = ReadFile(FullPath);
+
+ if (!File.ErrorCode)
+ {
+ Request.WriteResponse(ResponseCode, ContentType, File.Data[0]);
+ return true;
+ }
+ }
+
// The given content directory overrides any zip-fs discovered in the binary
if (!m_Directory.empty())
{