Bug fixing
This commit is contained in:
124
src/server.cpp
124
src/server.cpp
@@ -140,6 +140,120 @@ 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() {
|
||||
// Add CORS preflight handler for all routes
|
||||
server_.Options(".*", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
@@ -151,14 +265,14 @@ void Server::setup_routes() {
|
||||
add_cors_headers(req, res);
|
||||
});
|
||||
|
||||
const std::string welcome_page = "<html><body><h1>simple_object_storage Template Registry</h1></body></html>";
|
||||
|
||||
// Welcome page
|
||||
server_.Get("/", [welcome_page](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(welcome_page, "text/html");
|
||||
server_.Get("/", [](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(welcome_page(), "text/html");
|
||||
});
|
||||
|
||||
server_.Get("/index.html", [welcome_page](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(welcome_page, "text/html");
|
||||
server_.Get("/index.html", [](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(welcome_page(), "text/html");
|
||||
});
|
||||
|
||||
// Get object by hash or label:tag
|
||||
|
Reference in New Issue
Block a user