-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a basic HTML page for enterprise (#26)
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
4 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef SOURCEMETA_REGISTRY_ENTERPRISE_EXPLORER_H_ | ||
#define SOURCEMETA_REGISTRY_ENTERPRISE_EXPLORER_H_ | ||
|
||
#include <sourcemeta/hydra/http.h> | ||
#include <sourcemeta/hydra/httpserver.h> | ||
|
||
#include "enterprise_explorer.h" | ||
|
||
#include <sstream> // std::ostringstream | ||
|
||
static auto explorer_start(const std::string &title) -> std::ostringstream { | ||
std::ostringstream html; | ||
html << "<!DOCTYPE html>"; | ||
html << "<html lang=\"en\">"; | ||
html << "<head>"; | ||
html << "<title>"; | ||
html << title; | ||
html << "</title>"; | ||
html << "</head>"; | ||
html << "<body>"; | ||
return html; | ||
} | ||
|
||
static auto explorer_end(std::ostringstream &html, | ||
sourcemeta::hydra::http::ServerResponse &response, | ||
const sourcemeta::hydra::http::Status code) -> void { | ||
html << "</body>"; | ||
html << "</html>"; | ||
|
||
// TODO: On non-debug builds, add at least some sane level | ||
// of HTTP caching, maybe similar to how GitHub Pages does it? | ||
response.status(code); | ||
response.header("Content-Type", "text/html"); | ||
response.end(html.str()); | ||
} | ||
|
||
namespace sourcemeta::registry::enterprise { | ||
|
||
auto explore_index(sourcemeta::hydra::http::ServerResponse &response) -> void { | ||
std::ostringstream html{explorer_start("Sourcemeta Schemas")}; | ||
html << "Sourcemeta Schemas"; | ||
explorer_end(html, response, sourcemeta::hydra::http::Status::OK); | ||
} | ||
|
||
} // namespace sourcemeta::registry::enterprise | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
target_compile_definitions(schema_registry_server PRIVATE SOURCEMETA_REGISTRY_ENTERPRISE) | ||
cmake_path(GET CMAKE_CURRENT_LIST_FILE PARENT_PATH ENTERPRISE_SOURCE_DIR) | ||
target_sources(schema_registry_server PRIVATE "${ENTERPRISE_SOURCE_DIR}/enterprise_server.h") | ||
target_sources(schema_registry_server PRIVATE | ||
"${ENTERPRISE_SOURCE_DIR}/enterprise_server.h" | ||
"${ENTERPRISE_SOURCE_DIR}/enterprise_explorer.h") | ||
target_include_directories(schema_registry_server PRIVATE "${ENTERPRISE_SOURCE_DIR}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
GET {{base}} | ||
HTTP 404 | ||
Content-Type: application/json | ||
[Captures] | ||
current_request_id: header "X-Request-id" | ||
[Asserts] | ||
jsonpath "$.code" == 404 | ||
jsonpath "$.error" == "not-found" | ||
jsonpath "$.message" == "There is no schema at this URL" | ||
jsonpath "$.request" == "{{current_request_id}}" | ||
HTTP 200 | ||
Content-Type: text/html |