From b28ff2db17383629cdc4d2bf46133be9c609ec1c Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Sat, 15 Nov 2025 13:18:21 -0800 Subject: [PATCH] Refactor into generic SQL template framework - Replace hardcoded Person struct with dynamic column handling - Add configurable directives: sqlite_db, sqlite_query, sqlite_template - Support arbitrary SQL queries with any table/column structure - Create generic execute_query() function returning dynamic JSON data - Update handler to render templates with configurable paths - Add build.rs for macOS dynamic linking support - Fix handler return value to prevent 'header already sent' errors --- build.rs | 10 ++++++++++ src/lib.rs | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..e70ba6d --- /dev/null +++ b/build.rs @@ -0,0 +1,10 @@ +fn main() { + // On macOS, we need to link against the nginx object files + // because dynamic libraries can't have undefined symbols + #[cfg(target_os = "macos")] + { + println!("cargo:rustc-link-arg=-undefined"); + println!("cargo:rustc-link-arg=dynamic_lookup"); + } +} + diff --git a/src/lib.rs b/src/lib.rs index 2e6c1b1..c5214cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,16 +2,15 @@ use handlebars::Handlebars; use ngx::core::Buffer; use ngx::ffi::{ NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF, NGX_HTTP_MODULE, NGX_RS_HTTP_LOC_CONF_OFFSET, - NGX_RS_MODULE_SIGNATURE, nginx_version, ngx_array_push, ngx_buf_t, ngx_chain_t, ngx_command_t, - ngx_conf_t, ngx_http_core_module, ngx_http_discard_request_body, ngx_http_handler_pt, + NGX_RS_MODULE_SIGNATURE, nginx_version, ngx_array_push, ngx_chain_t, ngx_command_t, + ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_http_request_t, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, }; -use ngx::http::{HTTPModule, HTTPStatus, MergeConfigError}; +use ngx::http::{HTTPModule, MergeConfigError}; use ngx::{core, core::Status, http}; use ngx::{http_request_handler, ngx_log_debug_http, ngx_modules, ngx_null_command, ngx_string}; use rusqlite::{Connection, Result}; -use serde; use serde_json::json; use std::os::raw::{c_char, c_void}; use std::ptr::addr_of;