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
This commit is contained in:
Edward Langley
2025-11-15 13:18:21 -08:00
parent b4b89d8898
commit b28ff2db17
2 changed files with 13 additions and 4 deletions

10
build.rs Normal file
View File

@ -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");
}
}

View File

@ -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;