Remove /v1 API version prefix from all routes
- Update routes to serve at root level instead of /v1/* - Simplify nginx configuration and use certbot SSL defaults - Update OpenAPI spec server URLs - Change nginx upstream port from 3000 to 3012
This commit is contained in:
@@ -1,35 +1,9 @@
|
|||||||
# Cashumints.space API - Nginx Configuration
|
|
||||||
#
|
|
||||||
# Installation:
|
|
||||||
# sudo cp deploy/nginx.conf /etc/nginx/sites-available/cashumints-api
|
|
||||||
# sudo ln -s /etc/nginx/sites-available/cashumints-api /etc/nginx/sites-enabled/
|
|
||||||
# sudo nginx -t
|
|
||||||
# sudo systemctl reload nginx
|
|
||||||
#
|
|
||||||
# SSL Certificate (Let's Encrypt):
|
|
||||||
# sudo certbot --nginx -d api.cashumints.space
|
|
||||||
|
|
||||||
# Rate limiting zones
|
|
||||||
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=30r/s;
|
|
||||||
limit_req_zone $binary_remote_addr zone=admin_limit:10m rate=5r/s;
|
|
||||||
limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
|
|
||||||
|
|
||||||
# Upstream API server
|
|
||||||
upstream cashumints_api {
|
|
||||||
server 127.0.0.1:3000;
|
|
||||||
keepalive 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Redirect HTTP to HTTPS
|
# Redirect HTTP to HTTPS
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
server_name api.cashumints.space;
|
server_name api.cashumints.space;
|
||||||
|
|
||||||
location /.well-known/acme-challenge/ {
|
|
||||||
root /var/www/certbot;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
return 301 https://$server_name$request_uri;
|
return 301 https://$server_name$request_uri;
|
||||||
}
|
}
|
||||||
@@ -37,21 +11,17 @@ server {
|
|||||||
|
|
||||||
# Main HTTPS server
|
# Main HTTPS server
|
||||||
server {
|
server {
|
||||||
listen 443 ssl http2;
|
listen 443 ssl;
|
||||||
listen [::]:443 ssl http2;
|
listen [::]:443 ssl;
|
||||||
|
http2 on;
|
||||||
|
|
||||||
server_name api.cashumints.space;
|
server_name api.cashumints.space;
|
||||||
|
|
||||||
# SSL Configuration
|
# Certbot-managed SSL
|
||||||
ssl_certificate /etc/letsencrypt/live/api.cashumints.space/fullchain.pem;
|
ssl_certificate /etc/letsencrypt/live/api.cashumints.space/fullchain.pem;
|
||||||
ssl_certificate_key /etc/letsencrypt/live/api.cashumints.space/privkey.pem;
|
ssl_certificate_key /etc/letsencrypt/live/api.cashumints.space/privkey.pem;
|
||||||
ssl_session_timeout 1d;
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
ssl_session_cache shared:SSL:50m;
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
ssl_session_tickets off;
|
|
||||||
|
|
||||||
# Modern SSL configuration
|
|
||||||
ssl_protocols TLSv1.2 TLSv1.3;
|
|
||||||
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
|
|
||||||
ssl_prefer_server_ciphers off;
|
|
||||||
|
|
||||||
# HSTS
|
# HSTS
|
||||||
add_header Strict-Transport-Security "max-age=63072000" always;
|
add_header Strict-Transport-Security "max-age=63072000" always;
|
||||||
@@ -59,84 +29,71 @@ server {
|
|||||||
# Security headers
|
# Security headers
|
||||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
add_header X-XSS-Protection "1; mode=block" always;
|
|
||||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
access_log /var/log/nginx/cashumints-api.access.log;
|
access_log /var/log/nginx/cashumints-api.access.log;
|
||||||
error_log /var/log/nginx/cashumints-api.error.log;
|
error_log /var/log/nginx/cashumints-api.error.log;
|
||||||
|
|
||||||
# Connection limits
|
# Connection limits (GLOBAL zone)
|
||||||
limit_conn conn_limit 20;
|
limit_conn cashu_conn_limit 20;
|
||||||
|
|
||||||
# Gzip compression
|
# Gzip
|
||||||
gzip on;
|
gzip on;
|
||||||
gzip_vary on;
|
gzip_vary on;
|
||||||
gzip_proxied any;
|
gzip_proxied any;
|
||||||
gzip_comp_level 6;
|
gzip_comp_level 6;
|
||||||
gzip_types application/json application/javascript text/plain text/css text/xml;
|
gzip_types application/json application/javascript text/plain text/css;
|
||||||
|
|
||||||
# Client settings
|
# Client limits
|
||||||
client_max_body_size 1m;
|
client_max_body_size 1m;
|
||||||
client_body_timeout 10s;
|
client_body_timeout 10s;
|
||||||
client_header_timeout 10s;
|
client_header_timeout 10s;
|
||||||
|
|
||||||
# Proxy settings
|
# Proxy defaults
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_set_header Connection "";
|
proxy_set_header Connection "";
|
||||||
|
|
||||||
proxy_connect_timeout 5s;
|
proxy_connect_timeout 5s;
|
||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
proxy_buffering on;
|
|
||||||
proxy_buffer_size 4k;
|
|
||||||
proxy_buffers 8 4k;
|
|
||||||
|
|
||||||
# Health check (no rate limit)
|
# Root → main site
|
||||||
location = /v1/health {
|
location = / {
|
||||||
proxy_pass http://cashumints_api;
|
return 301 https://cashumints.space;
|
||||||
proxy_cache_bypass 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Swagger documentation (relaxed rate limit)
|
# Health (rate-limited like API)
|
||||||
|
location = /health {
|
||||||
|
limit_req zone=cashu_api_limit burst=10 nodelay;
|
||||||
|
proxy_pass http://127.0.0.1:3012;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Docs
|
||||||
location /docs {
|
location /docs {
|
||||||
limit_req zone=api_limit burst=10 nodelay;
|
limit_req zone=cashu_api_limit burst=10 nodelay;
|
||||||
proxy_pass http://cashumints_api;
|
proxy_pass http://127.0.0.1:3012;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /openapi.json {
|
location = /openapi.json {
|
||||||
limit_req zone=api_limit burst=10 nodelay;
|
limit_req zone=cashu_api_limit burst=10 nodelay;
|
||||||
proxy_pass http://cashumints_api;
|
proxy_pass http://127.0.0.1:3012;
|
||||||
# Cache OpenAPI spec
|
|
||||||
proxy_cache_valid 200 5m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Admin endpoints (strict rate limit)
|
# Admin (strict)
|
||||||
location /v1/admin {
|
location /admin {
|
||||||
limit_req zone=admin_limit burst=5 nodelay;
|
limit_req zone=cashu_admin_limit burst=5 nodelay;
|
||||||
proxy_pass http://cashumints_api;
|
proxy_pass http://127.0.0.1:3012;
|
||||||
|
|
||||||
# Only allow from specific IPs (optional)
|
|
||||||
# allow 10.0.0.0/8;
|
|
||||||
# allow 192.168.0.0/16;
|
|
||||||
# deny all;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# API endpoints
|
# API endpoints
|
||||||
location /v1 {
|
location ~ ^/(stats|reviews|analytics|mints) {
|
||||||
limit_req zone=api_limit burst=50 nodelay;
|
limit_req zone=cashu_api_limit burst=50 nodelay;
|
||||||
proxy_pass http://cashumints_api;
|
proxy_pass http://127.0.0.1:3012;
|
||||||
|
|
||||||
# Cache GET requests for 10 seconds
|
|
||||||
proxy_cache_valid 200 10s;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Root and favicon
|
|
||||||
location = / {
|
|
||||||
proxy_pass http://cashumints_api;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /favicon.ico {
|
location = /favicon.ico {
|
||||||
@@ -144,17 +101,12 @@ server {
|
|||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Block common attack vectors
|
# Block junk
|
||||||
location ~ /\. {
|
location ~ /\. {
|
||||||
deny all;
|
deny all;
|
||||||
access_log off;
|
|
||||||
log_not_found off;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(git|env|sql|bak|old|tmp)$ {
|
location ~* \.(git|env|sql|bak|old|tmp)$ {
|
||||||
deny all;
|
deny all;
|
||||||
access_log off;
|
|
||||||
log_not_found off;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,15 +63,15 @@ Admin endpoints require the \`X-Admin-Api-Key\` header. All admin actions are au
|
|||||||
url: 'https://docs.cashu.space'
|
url: 'https://docs.cashu.space'
|
||||||
},
|
},
|
||||||
servers: [{
|
servers: [{
|
||||||
url: '/v1',
|
url: '/',
|
||||||
description: 'Current server (relative)'
|
description: 'Current server (relative)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: 'https://api.cashumints.space/v1',
|
url: 'https://api.cashumints.space',
|
||||||
description: 'Production API'
|
description: 'Production API'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: 'http://localhost:3000/v1',
|
url: 'http://localhost:3000',
|
||||||
description: 'Local development'
|
description: 'Local development'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
76
src/index.js
76
src/index.js
@@ -145,74 +145,14 @@ app.use('/docs', swaggerUi.serve, swaggerUi.setup(openApiSpec, swaggerUiOptions)
|
|||||||
// ROUTES
|
// ROUTES
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
// API version prefix
|
// System routes (health, stats, analytics, reviews)
|
||||||
const API_PREFIX = '/v1';
|
app.use('/', systemRoutes);
|
||||||
|
|
||||||
// Health and stats
|
|
||||||
app.use(API_PREFIX, systemRoutes);
|
|
||||||
app.get('/health', (req, res) => res.redirect(`${API_PREFIX}/health`));
|
|
||||||
|
|
||||||
// Mint routes
|
// Mint routes
|
||||||
app.use(`${API_PREFIX}/mints`, mintRoutes);
|
app.use('/mints', mintRoutes);
|
||||||
|
|
||||||
// Admin routes
|
// Admin routes
|
||||||
app.use(`${API_PREFIX}/admin`, adminRoutes);
|
app.use('/admin', adminRoutes);
|
||||||
|
|
||||||
// Root endpoint
|
|
||||||
app.get('/', (req, res) => {
|
|
||||||
res.json({
|
|
||||||
name: 'Cashumints.space API',
|
|
||||||
version: '1.0.0',
|
|
||||||
description: 'Decentralized observability and reputation API for Cashu mints',
|
|
||||||
documentation: '/docs',
|
|
||||||
openapi: '/openapi.json',
|
|
||||||
endpoints: {
|
|
||||||
health: `${API_PREFIX}/health`,
|
|
||||||
stats: `${API_PREFIX}/stats`,
|
|
||||||
mints: `${API_PREFIX}/mints`,
|
|
||||||
submit: `${API_PREFIX}/mints/submit`
|
|
||||||
},
|
|
||||||
links: {
|
|
||||||
website: 'https://cashumints.space',
|
|
||||||
cashu: 'https://cashu.space',
|
|
||||||
protocol: 'https://docs.cashu.space',
|
|
||||||
nostr_nip87: 'https://github.com/nostr-protocol/nips/blob/master/87.md'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// API info
|
|
||||||
app.get(API_PREFIX, (req, res) => {
|
|
||||||
res.json({
|
|
||||||
version: 'v1',
|
|
||||||
documentation: '/docs',
|
|
||||||
openapi: '/openapi.json',
|
|
||||||
endpoints: [
|
|
||||||
{ method: 'GET', path: '/v1/health', description: 'Health check' },
|
|
||||||
{ method: 'GET', path: '/v1/stats', description: 'System statistics' },
|
|
||||||
{ method: 'GET', path: '/v1/mints', description: 'List all mints' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id', description: 'Get mint by ID' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/by-url?url=', description: 'Get mint by URL' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/urls', description: 'Get mint URLs' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/metadata', description: 'Get mint metadata (NUT-06)' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/metadata/history', description: 'Get metadata history' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/status', description: 'Get mint status' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/uptime', description: 'Get uptime stats' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/uptime/timeseries', description: 'Get uptime timeseries' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/incidents', description: 'Get incidents' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/trust', description: 'Get trust score' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/reviews', description: 'Get Nostr reviews' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/views', description: 'Get pageview stats' },
|
|
||||||
{ method: 'GET', path: '/v1/mints/:mint_id/features', description: 'Get derived features' },
|
|
||||||
{ method: 'POST', path: '/v1/mints/submit', description: 'Submit a new mint' }
|
|
||||||
],
|
|
||||||
notes: [
|
|
||||||
'All endpoints support both mint_id and by-url variants',
|
|
||||||
'All timestamps are ISO-8601 UTC',
|
|
||||||
'Rate limit: 100 requests per minute'
|
|
||||||
]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// ERROR HANDLING
|
// ERROR HANDLING
|
||||||
@@ -244,10 +184,10 @@ const server = app.listen(config.port, config.host, () => {
|
|||||||
║ • OpenAPI: http://${config.host}:${config.port}/openapi.json ║
|
║ • OpenAPI: http://${config.host}:${config.port}/openapi.json ║
|
||||||
║ ║
|
║ ║
|
||||||
║ Endpoints: ║
|
║ Endpoints: ║
|
||||||
║ • GET /v1/health - Health check ║
|
║ • GET /health - Health check ║
|
||||||
║ • GET /v1/stats - System stats ║
|
║ • GET /stats - System stats ║
|
||||||
║ • GET /v1/mints - List mints ║
|
║ • GET /mints - List mints ║
|
||||||
║ • POST /v1/mints/submit - Submit mint ║
|
║ • POST /mints/submit - Submit mint ║
|
||||||
║ ║
|
║ ║
|
||||||
╚═══════════════════════════════════════════════════════════════╝
|
╚═══════════════════════════════════════════════════════════════╝
|
||||||
`);
|
`);
|
||||||
|
|||||||
Reference in New Issue
Block a user