Bug fixing
This commit is contained in:
115
src/server.cpp
115
src/server.cpp
@@ -15,6 +15,7 @@
|
|||||||
#include "string_utils.hpp" // Include the new utility header
|
#include "string_utils.hpp" // Include the new utility header
|
||||||
#include "put_handler.hpp"
|
#include "put_handler.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include "welcome_page.hpp"
|
||||||
|
|
||||||
namespace simple_object_storage {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
@@ -140,120 +141,6 @@ void Server::stop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string welcome_page() {
|
|
||||||
return R"(
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Simple Object Storage</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
||||||
line-height: 1.6;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
background-color: #f5f7fa;
|
|
||||||
color: #2d3748;
|
|
||||||
}
|
|
||||||
.container {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
header {
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 3rem;
|
|
||||||
padding: 2rem 0;
|
|
||||||
background-color: #fff;
|
|
||||||
border-radius: 8px;
|
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
color: #2b6cb0;
|
|
||||||
margin: 0;
|
|
||||||
font-size: 2.5rem;
|
|
||||||
}
|
|
||||||
.subtitle {
|
|
||||||
color: #4a5568;
|
|
||||||
margin-top: 0.5rem;
|
|
||||||
font-size: 1.2rem;
|
|
||||||
}
|
|
||||||
.features {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
||||||
gap: 1.5rem;
|
|
||||||
margin-top: 2rem;
|
|
||||||
}
|
|
||||||
.feature-card {
|
|
||||||
background: white;
|
|
||||||
padding: 1.5rem;
|
|
||||||
border-radius: 8px;
|
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
||||||
}
|
|
||||||
.feature-card h3 {
|
|
||||||
color: #2b6cb0;
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
.endpoints {
|
|
||||||
background: white;
|
|
||||||
padding: 1.5rem;
|
|
||||||
border-radius: 8px;
|
|
||||||
margin-top: 2rem;
|
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
||||||
}
|
|
||||||
.endpoints h2 {
|
|
||||||
color: #2b6cb0;
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: #f1f5f9;
|
|
||||||
padding: 0.2rem 0.4rem;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: 'Courier New', Courier, monospace;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<header>
|
|
||||||
<h1>Simple Object Storage</h1>
|
|
||||||
<p class="subtitle">A lightweight, efficient object storage service</p>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="features">
|
|
||||||
<div class="feature-card">
|
|
||||||
<h3>Simple Storage</h3>
|
|
||||||
<p>Store and retrieve objects using unique hashes or label:tag combinations.</p>
|
|
||||||
</div>
|
|
||||||
<div class="feature-card">
|
|
||||||
<h3>RESTful API</h3>
|
|
||||||
<p>Access your objects through a clean, intuitive REST API interface.</p>
|
|
||||||
</div>
|
|
||||||
<div class="feature-card">
|
|
||||||
<h3>Secure Access</h3>
|
|
||||||
<p>Protected endpoints with token-based authentication for write operations.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="endpoints">
|
|
||||||
<h2>Available Endpoints</h2>
|
|
||||||
<ul>
|
|
||||||
<li><code>GET /object/{hash}</code> - Retrieve an object by hash</li>
|
|
||||||
<li><code>GET /hash/{label:tag}</code> - Get hash for a label:tag</li>
|
|
||||||
<li><code>GET /exists/{hash}</code> - Check if an object exists</li>
|
|
||||||
<li><code>GET /dir</code> - List all objects</li>
|
|
||||||
<li><code>PUT /upload</code> - Upload a new object</li>
|
|
||||||
<li><code>GET /meta/{hash}</code> - Get object metadata</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
)";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Server::setup_routes() {
|
void Server::setup_routes() {
|
||||||
// Add CORS preflight handler for all routes
|
// Add CORS preflight handler for all routes
|
||||||
server_.Options(".*", [this](const httplib::Request& req, httplib::Response& res) {
|
server_.Options(".*", [this](const httplib::Request& req, httplib::Response& res) {
|
||||||
|
114
src/welcome_page.cpp
Normal file
114
src/welcome_page.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#include "welcome_page.hpp"
|
||||||
|
|
||||||
|
namespace simple_object_storage {
|
||||||
|
|
||||||
|
std::string welcome_page() {
|
||||||
|
return R"(
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Simple Object Storage</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
line-height: 1.6;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
color: #2d3748;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 3rem;
|
||||||
|
padding: 2rem 0;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #2b6cb0;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 2.5rem;
|
||||||
|
}
|
||||||
|
.subtitle {
|
||||||
|
color: #4a5568;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
.features {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||||
|
gap: 1.5rem;
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
.feature-card {
|
||||||
|
background: white;
|
||||||
|
padding: 1.5rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
.feature-card h3 {
|
||||||
|
color: #2b6cb0;
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
.endpoints {
|
||||||
|
background: white;
|
||||||
|
padding: 1.5rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-top: 2rem;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
.endpoints h2 {
|
||||||
|
color: #2b6cb0;
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
code {
|
||||||
|
background: #f1f5f9;
|
||||||
|
padding: 0.2rem 0.4rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: 'Courier New', Courier, monospace;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<h1>Simple Object Storage</h1>
|
||||||
|
<p class="subtitle">A lightweight, simple object storage service</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="features">
|
||||||
|
<div class="feature-card">
|
||||||
|
<h3>Simple Storage</h3>
|
||||||
|
<p>Store and retrieve objects using unique hashes or label:tag combinations.</p>
|
||||||
|
</div>
|
||||||
|
<div class="feature-card">
|
||||||
|
<h3>RESTful API</h3>
|
||||||
|
<p>Access objects through a clean, intuitive REST API interface.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="endpoints">
|
||||||
|
<h2>Available Endpoints</h2>
|
||||||
|
<ul>
|
||||||
|
<li><code>GET /object/{hash}</code> - Retrieve an object by hash</li>
|
||||||
|
<li><code>GET /hash/{label:tag}</code> - Get hash for a label:tag</li>
|
||||||
|
<li><code>GET /exists/{hash}</code> - Check if an object exists</li>
|
||||||
|
<li><code>GET /dir</code> - List all objects</li>
|
||||||
|
<li><code>GET /meta/{hash}</code> - Get object metadata</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace simple_object_storage
|
9
src/welcome_page.hpp
Normal file
9
src/welcome_page.hpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace simple_object_storage {
|
||||||
|
|
||||||
|
std::string welcome_page();
|
||||||
|
|
||||||
|
} // namespace simple_object_storage
|
Reference in New Issue
Block a user