From c0489ff4d97b53ba2267e571a27917c4692f4702 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 May 2025 22:33:19 +1200 Subject: [PATCH] :-'Generic Commit' --- build.sh | 2 -- publish.sh | 2 -- src/server.cpp | 31 ++++++++++++++++--------------- test.sh | 13 +++++++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/build.sh b/build.sh index f7f0da5..2f3d7d9 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,6 @@ set -e # DIRECTORIES SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -CACHE_DIR="${SCRIPT_DIR}/cache" EXE_DIR="${SCRIPT_DIR}/output" PROJECTNAME="simple_object_storage" @@ -62,7 +61,6 @@ cp build_arm64/${PROJECTNAME} ${EXE_DIR}/${PROJECTNAME}.arm64 #-------------------------------- cd $SCRIPT_DIR -mkdir -p ${CACHE_DIR} mkdir -p ${EXE_DIR} BUILDSTR="amd64" diff --git a/publish.sh b/publish.sh index 046c1a6..c2c9852 100755 --- a/publish.sh +++ b/publish.sh @@ -5,9 +5,7 @@ set -e # DIRECTORIES SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -#CACHE_DIR="${SCRIPT_DIR}/cache" EXE_DIR="${SCRIPT_DIR}/output" -#BUILD_DIR="${SCRIPT_DIR}/build" # FUNCTIONS function title() { diff --git a/src/server.cpp b/src/server.cpp index 9d33d97..060b70b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -153,25 +153,10 @@ void Server::setup_routes() { }); - // Welcome page - server_.Get("/(.*)", [this](const httplib::Request& req, httplib::Response& res) { - if (req.path == "/") { - res.set_content(welcome_page(), "text/html"); - return; - } - // if the path is not /, then it's a hash or label:tag - handle_get_object(req, res); - }); - server_.Get("/index.html", [](const httplib::Request&, httplib::Response& res) { res.set_content(welcome_page(), "text/html"); }); - // Get object by hash or label:tag - server_.Get("/object/(.*)", [this](const httplib::Request& req, httplib::Response& res) { - handle_get_object(req, res); - }); - // Get hash for label:tag server_.Get("/hash/(.*)", [this](const httplib::Request& req, httplib::Response& res) { handle_get_hash(req, res); @@ -218,6 +203,22 @@ void Server::setup_routes() { server_.Get("/status", [this](const httplib::Request& req, httplib::Response& res) { res.set_content(nlohmann::json({{"result", "success"}, {"status", "ok"}}).dump(), "application/json"); }); + + // Get object by hash or label:tag + server_.Get("/object/(.*)", [this](const httplib::Request& req, httplib::Response& res) { + handle_get_object(req, res); + }); + + // Welcome page and download object. + server_.Get("/(.*)", [this](const httplib::Request& req, httplib::Response& res) { + if (req.path == "/") { + res.set_content(welcome_page(), "text/html"); + return; + } + // if the path is not /, then it's a hash or label:tag + handle_get_object(req, res); + }); + } void Server::handle_cors_preflight(const httplib::Request& req, httplib::Response& res) { diff --git a/test.sh b/test.sh index d9054e1..3d1bf8e 100755 --- a/test.sh +++ b/test.sh @@ -3,10 +3,7 @@ set -euo pipefail -HOSTURL="$1" -if [ -z "${HOSTURL}" ]; then - HOSTURL="http://localhost:8123" -fi +HOSTURL="${1:-http://localhost:8123}" #------------------------------------------------------------------------------------------------ @@ -37,6 +34,14 @@ cat << EOF EOF + +title "TESTING ${HOSTURL}" + +cat << EOF + + +EOF + # Test 0: Verify the script is running title "0: Verify the server is running"