# 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 info; 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 "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 { 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 { 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 { 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 "