feat: stub agent file structure
This commit is contained in:
50
crates/nxmesh-agent/src/nginx/config_renderer.rs
Normal file
50
crates/nxmesh-agent/src/nginx/config_renderer.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
//! Nginx configuration renderer
|
||||
|
||||
use handlebars::Handlebars;
|
||||
use serde_json::json;
|
||||
|
||||
/// Configuration renderer
|
||||
pub struct ConfigRenderer {
|
||||
handlebars: Handlebars<'static>,
|
||||
}
|
||||
|
||||
impl ConfigRenderer {
|
||||
/// Create a new config renderer
|
||||
pub fn new() -> Self {
|
||||
let mut handlebars = Handlebars::new();
|
||||
|
||||
// Register built-in templates
|
||||
Self::register_templates(&mut handlebars);
|
||||
|
||||
Self { handlebars }
|
||||
}
|
||||
|
||||
/// Register built-in templates
|
||||
fn register_templates(handlebars: &mut Handlebars) {
|
||||
// Default reverse proxy template
|
||||
handlebars.register_template_string("default", include_str!("templates/default.hbs")).ok();
|
||||
}
|
||||
|
||||
/// Render configuration
|
||||
pub fn render(&self, template_name: &str, data: &serde_json::Value) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let rendered = self.handlebars.render(template_name, data)?;
|
||||
Ok(rendered)
|
||||
}
|
||||
|
||||
/// Render virtual host
|
||||
pub fn render_virtual_host(&self, vh: &nxmesh_core::models::VirtualHost) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let data = json!({
|
||||
"server_name": vh.server_name,
|
||||
"listen_port": vh.listen_port,
|
||||
"ssl_enabled": vh.ssl_enabled,
|
||||
"locations": vh.locations,
|
||||
});
|
||||
self.render("default", &data)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ConfigRenderer {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user