Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a basic HTML page for enterprise #26

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/enterprise/enterprise_explorer.h
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
9 changes: 9 additions & 0 deletions src/enterprise/enterprise_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@

#include <sourcemeta/hydra/httpserver.h>

#include "enterprise_explorer.h"

namespace sourcemeta::registry::enterprise {

auto on_index(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response) -> void {
explore_index(response);
}

auto attach(sourcemeta::hydra::http::Server &server) -> void {
server.route(sourcemeta::hydra::http::Method::GET, "/", on_index);
server.route(sourcemeta::hydra::http::Method::GET, "/*", ::on_request);
server.route(sourcemeta::hydra::http::Method::HEAD, "/*", ::on_request);
server.otherwise(::on_otherwise);
Expand Down
4 changes: 3 additions & 1 deletion src/enterprise/server.cmake
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}")
11 changes: 2 additions & 9 deletions test/e2e/ee/root.hurl
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