New Feature: sqlite_param Directive - Allows passing nginx variables as SQL prepared statement parameters - Supports query parameters ($arg_name), path captures ($1, $2), headers, etc. - Safe SQL injection protection via rusqlite prepared statements - Multiple parameters supported (bound in order to ? placeholders) Implementation: - New sqlite_param directive for adding query parameters - Variable resolution using ngx_http_get_variable() FFI - UTF-8 validation on all variable values - Updated execute_query() to accept parameter array - rusqlite::ToSql parameter binding Examples: - Book detail by ID: /book?id=1 - Genre filtering: /genre?genre=Programming - Year range search: /years?min=2015&max=2024 New Files: - conf/book_detail.conf: Parameter examples configuration - server_root/book/detail.hbs: Book detail page template - server_root/genre/genre.hbs: Genre filter page template - start_book_detail.sh: Quick start script for params example - README.md: Comprehensive project documentation - README_PARAMETERS.md: Parameters feature documentation Configuration: - MainConfig now supports global_templates_dir - ModuleConfig extended with query_params Vec - Handler resolves variables at request time - Template paths adjusted for exact location matches All examples tested and working with both static and parameterized queries.
40 lines
1.2 KiB
Bash
Executable File
40 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Start script for the book detail example with path parameters
|
|
|
|
set -e
|
|
|
|
echo "📚 Starting Book Detail Example with Path Parameters..."
|
|
echo ""
|
|
|
|
# Check if database exists
|
|
if [ ! -f "book_catalog.db" ]; then
|
|
echo "Database not found. Running setup..."
|
|
./setup_book_catalog.sh
|
|
echo ""
|
|
fi
|
|
|
|
# Check if module is built
|
|
if [ ! -f "target/debug/libnginx_test.dylib" ]; then
|
|
echo "Module not built. Building..."
|
|
direnv exec "$PWD" cargo build
|
|
echo ""
|
|
fi
|
|
|
|
# Start nginx
|
|
echo "Starting nginx on http://localhost:8081"
|
|
./ngx_src/nginx-1.28.0/objs/nginx -c conf/book_detail.conf -p .
|
|
|
|
echo ""
|
|
echo "✅ Book Detail Example is running!"
|
|
echo ""
|
|
echo "Try these URLs:"
|
|
echo " • http://localhost:8081/book?id=1 - View book #1"
|
|
echo " • http://localhost:8081/book?id=5 - View book #5"
|
|
echo " • http://localhost:8081/genre?genre=Programming - Programming books"
|
|
echo " • http://localhost:8081/genre?genre=Databases - Database books"
|
|
echo " • http://localhost:8081/years?min=2000&max=2010 - Books from 2000-2010"
|
|
echo " • http://localhost:8081/years?min=2015&max=2024 - Books from 2015-2024"
|
|
echo ""
|
|
echo "To stop: ./ngx_src/nginx-1.28.0/objs/nginx -s stop -c conf/book_detail.conf -p ."
|
|
|