feat: SEO + Nginx optimization
Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 21s
Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 21s
- Update sitemap.xml to include /v1/health endpoint - Add proper 404 handling (JSON for API paths, HTML for browser paths) - Create optimized nginx config with gzip, cache headers, specific locations - Add logrotate configuration for DocFast logs - Add security headers and static asset caching
This commit is contained in:
parent
9541ae1826
commit
210e71e3d8
4 changed files with 152 additions and 0 deletions
48
src/index.ts
48
src/index.ts
|
|
@ -183,6 +183,54 @@ app.get("/api", (_req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// 404 handler - must be after all routes
|
||||
app.use((req, res) => {
|
||||
// Check if it's an API request
|
||||
const isApiRequest = req.path.startsWith('/v1/') || req.path.startsWith('/api') || req.path.startsWith('/health');
|
||||
|
||||
if (isApiRequest) {
|
||||
// JSON 404 for API paths
|
||||
res.status(404).json({
|
||||
error: "Not Found",
|
||||
message: `The requested endpoint ${req.method} ${req.path} does not exist`,
|
||||
statusCode: 404,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
} else {
|
||||
// HTML 404 for browser paths
|
||||
res.status(404).send(`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>404 - Page Not Found | DocFast</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>⚡</text></svg>">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: 'Inter', sans-serif; background: #0b0d11; color: #e4e7ed; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
|
||||
.container { background: #151922; border: 1px solid #1e2433; border-radius: 16px; padding: 48px; max-width: 520px; width: 100%; text-align: center; }
|
||||
h1 { font-size: 3rem; margin-bottom: 12px; font-weight: 700; color: #34d399; }
|
||||
h2 { font-size: 1.5rem; margin-bottom: 16px; font-weight: 600; }
|
||||
p { color: #7a8194; margin-bottom: 24px; line-height: 1.6; }
|
||||
a { color: #34d399; text-decoration: none; font-weight: 600; }
|
||||
a:hover { color: #5eead4; }
|
||||
.emoji { font-size: 4rem; margin-bottom: 24px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="emoji">⚡</div>
|
||||
<h1>404</h1>
|
||||
<h2>Page Not Found</h2>
|
||||
<p>The page you're looking for doesn't exist or has been moved.</p>
|
||||
<p><a href="/">← Back to DocFast</a> | <a href="/docs">Read the docs</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>`);
|
||||
}
|
||||
});
|
||||
|
||||
async function start() {
|
||||
// Initialize PostgreSQL
|
||||
await initDatabase();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue