From 95581dbaa6a3b60ab61643105b247ae21e0687c8 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 20 Dec 2017 22:35:26 -0800 Subject: [PATCH] Pass common plugin chain into web handler --- src/bin.rs | 2 +- src/web.rs | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 57520201..4cc0aa1c 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -207,7 +207,7 @@ fn main() { println!("Server listening on port {}", port); - web::start(config.clone(), project.clone(), vfs.clone()); + web::start(config.clone(), project.clone(), &PLUGIN_CHAIN, vfs.clone()); }, ("pack", _) => { eprintln!("'rojo pack' is not yet implemented!"); diff --git a/src/web.rs b/src/web.rs index f4237a1e..c9aef861 100644 --- a/src/web.rs +++ b/src/web.rs @@ -10,7 +10,6 @@ use project::Project; use vfs::{Vfs, VfsChange}; use rbx::RbxItem; use plugin::PluginChain; -use plugins::{ScriptPlugin, DefaultPlugin}; static MAX_BODY_SIZE: usize = 25 * 1024 * 1025; // 25 MiB @@ -102,19 +101,11 @@ where Some(parsed) } -pub fn start(config: Config, project: Project, vfs: Arc>) { +pub fn start(config: Config, project: Project, plugin_chain: &'static PluginChain, vfs: Arc>) { let address = format!("localhost:{}", config.port); let server_id = config.server_id.to_string(); - // Fine, rouille, I'll put things in a 'static Arc... - lazy_static! { - static ref PLUGIN_CHAIN: Arc> = Arc::new(Mutex::new(PluginChain::new(vec![ - Box::new(ScriptPlugin::new()), - Box::new(DefaultPlugin::new()), - ]))); - } - rouille::start_server(address, move |request| { router!(request, (GET) (/) => { @@ -146,8 +137,6 @@ pub fn start(config: Config, project: Project, vfs: Arc>) { }, (POST) (/read) => { - let plugin_chain = PLUGIN_CHAIN.lock().unwrap(); - let read_request: Vec> = match read_json(&request) { Some(v) => v, None => return rouille::Response::empty_400(), @@ -188,8 +177,6 @@ pub fn start(config: Config, project: Project, vfs: Arc>) { }, (POST) (/write) => { - let _plugin_chain = PLUGIN_CHAIN.lock().unwrap(); - let _write_request: Vec = match read_json(&request) { Some(v) => v, None => return rouille::Response::empty_400(),