//! plugin-domain —— 动态域名插件。 //! //! 职责:子域名 → 后端映射(`sub:` 键空间)、申请与审批、转发决策 //! (access 阶段查共享内存)。数据文件 `data/domains.json`。 //! //! ## 与旧版最大的差异:写穿 //! //! 热路径**永不回源**(未命中即 404),所以每个写操作都必须 //! **同时更新共享内存与文件**——这就是 `domains::sync_shm` 的存在理由。 //! 漏掉一处,就会出现「审核通过了但立刻 404」。 //! //! ## 装配点(gateway) //! //! * `preconfig` —— 注册 `$proxy_backend_addr` 变量(`proxy_pass` 依赖) //! * `postconfig` —— 注册 `ResolveHandler`(access 阶段) //! * `zone_load` —— 全量装载 `sub:` 映射 //! * `dispatch_api` —— 认领域名类管理/账号端点 pub mod api; pub mod config; pub mod domains; pub mod models; pub mod resolve; pub mod store; use ngx::core::Status; use ngx::ffi::{ngx_conf_t, ngx_http_request_t}; use ipass_core::plugin::Plugin; pub struct DomainPlugin; impl Plugin for DomainPlugin { fn name(&self) -> &'static str { "domain" } fn preconfig(&self, cf: *mut ngx_conf_t) -> bool { resolve::preconfig(cf) } fn postconfig(&self, cf: *mut ngx_conf_t) -> bool { // SAFETY: cf 由 nginx 传入且有效 ngx::http::add_phase_handler::(unsafe { &mut *cf }).is_ok() } fn dispatch_api(&self, r: *mut ngx_http_request_t) -> Option { api::dispatch(r) } fn zone_load(&self) -> usize { domains::reload_shm() } }