{{title}}
+ +{{description}}
+ + View Details → +diff --git a/conf/sqlite_serve.conf b/conf/sqlite_serve.conf new file mode 100644 index 0000000..c42bd2e --- /dev/null +++ b/conf/sqlite_serve.conf @@ -0,0 +1,114 @@ +# 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 warn; + +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 "