Files
nginx-serve/conf/sqlite_serve.conf
Edward Langley 86b79c0a85 Implement structured logging with ngx_log_error_core
Logging now uses nginx's native error log with proper levels:
- ERROR (level 3): Configuration/query/template failures
- WARN (level 4): Missing parameters
- INFO (level 6): Request processing, template resolution
- DEBUG (level 7): Detailed tracing

Log Format: [sqlite-serve:module] message

Example output:
- [info] [sqlite-serve:handler] Processing request for /books
- [info] [sqlite-serve:template] Resolved template: ./server_root/books/catalog.hbs
- [info] [sqlite-serve:params] Resolved 1 parameters
- [notice] [sqlite-serve:success] Rendered catalog.hbs with 1 params

Specialized logging functions:
- log_config_error(): Invalid configuration
- log_query_error(): SQL errors with query shown
- log_template_error(): Template failures with path
- log_param_error(): Parameter resolution issues
- log_request_success(): Successful processing info
- log_template_loading(): Template discovery

Uses ngx_log_error_core() C API directly for dynamic messages.

Test Coverage: 59 tests
Configuration: error_log set to debug level for visibility
2025-11-15 17:05:09 -08:00

115 lines
3.7 KiB
Plaintext

# sqlite-serve - Unified Production Example
# Demonstrates all features: static queries, positional params, named params, templates
load_module target/debug/libsqlite_serve.dylib;
worker_processes auto;
events {
worker_connections 1024;
}
error_log logs/error.log debug;
http {
# Global templates for shared components
sqlite_global_templates "server_root/global_templates";
# MIME types
types {
text/html html htm;
text/css css;
application/javascript js;
}
default_type text/html;
# Performance optimizations
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
server {
listen 8080;
server_name localhost;
root "server_root";
charset utf-8;
# Serve static CSS file
location /static/ {
add_header "Content-Type" "text/css; charset=utf-8";
add_header "Cache-Control" "public, max-age=31536000";
}
# Homepage - Redirect to catalog
location = / {
return 302 /books;
}
# Browse all books
location = /books {
add_header "Content-Type" "text/html; charset=utf-8";
add_header "Cache-Control" "public, max-age=300";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books ORDER BY rating DESC, title";
sqlite_template "catalog.hbs";
}
# Book detail by ID (named parameter)
location = /book {
add_header "Content-Type" "text/html; charset=utf-8";
add_header "Cache-Control" "public, max-age=300";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE id = :book_id";
sqlite_param :book_id $arg_id;
sqlite_template "detail.hbs";
}
# Filter by genre (named parameter)
location = /genre {
add_header "Content-Type" "text/html; charset=utf-8";
add_header "Cache-Control" "public, max-age=300";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE genre = :genre ORDER BY rating DESC, title";
sqlite_param :genre $arg_genre;
sqlite_template "catalog.hbs";
}
# Search by title (named parameter with LIKE)
location = /search {
add_header "Content-Type" "text/html; charset=utf-8";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE title LIKE '%' || :q || '%' ORDER BY rating DESC";
sqlite_param :q $arg_q;
sqlite_template "catalog.hbs";
}
# Filter by minimum rating (named parameter)
location = /top {
add_header "Content-Type" "text/html; charset=utf-8";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE rating >= :min_rating ORDER BY rating DESC, title";
sqlite_param :min_rating $arg_min;
sqlite_template "catalog.hbs";
}
# Year range filter (multiple named parameters)
location = /era {
add_header "Content-Type" "text/html; charset=utf-8";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE year >= :from AND year <= :to ORDER BY year DESC, title";
sqlite_param :from $arg_from;
sqlite_param :to $arg_to;
sqlite_template "catalog.hbs";
}
# 404 handler
location @notfound {
add_header "Content-Type" "text/html; charset=utf-8";
return 404 "<html><body><h1>404 Not Found</h1><p><a href='/books'>Back to catalog</a></p></body></html>";
}
}
}