Pass common plugin chain into web handler

This commit is contained in:
Lucien Greathouse
2017-12-20 22:35:26 -08:00
parent aaaf3ba0b9
commit 95581dbaa6
2 changed files with 2 additions and 15 deletions

View File

@@ -207,7 +207,7 @@ fn main() {
println!("Server listening on port {}", port); 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", _) => { ("pack", _) => {
eprintln!("'rojo pack' is not yet implemented!"); eprintln!("'rojo pack' is not yet implemented!");

View File

@@ -10,7 +10,6 @@ use project::Project;
use vfs::{Vfs, VfsChange}; use vfs::{Vfs, VfsChange};
use rbx::RbxItem; use rbx::RbxItem;
use plugin::PluginChain; use plugin::PluginChain;
use plugins::{ScriptPlugin, DefaultPlugin};
static MAX_BODY_SIZE: usize = 25 * 1024 * 1025; // 25 MiB static MAX_BODY_SIZE: usize = 25 * 1024 * 1025; // 25 MiB
@@ -102,19 +101,11 @@ where
Some(parsed) Some(parsed)
} }
pub fn start(config: Config, project: Project, vfs: Arc<Mutex<Vfs>>) { pub fn start(config: Config, project: Project, plugin_chain: &'static PluginChain, vfs: Arc<Mutex<Vfs>>) {
let address = format!("localhost:{}", config.port); let address = format!("localhost:{}", config.port);
let server_id = config.server_id.to_string(); let server_id = config.server_id.to_string();
// Fine, rouille, I'll put things in a 'static Arc<Mutex>...
lazy_static! {
static ref PLUGIN_CHAIN: Arc<Mutex<PluginChain>> = Arc::new(Mutex::new(PluginChain::new(vec![
Box::new(ScriptPlugin::new()),
Box::new(DefaultPlugin::new()),
])));
}
rouille::start_server(address, move |request| { rouille::start_server(address, move |request| {
router!(request, router!(request,
(GET) (/) => { (GET) (/) => {
@@ -146,8 +137,6 @@ pub fn start(config: Config, project: Project, vfs: Arc<Mutex<Vfs>>) {
}, },
(POST) (/read) => { (POST) (/read) => {
let plugin_chain = PLUGIN_CHAIN.lock().unwrap();
let read_request: Vec<Vec<String>> = match read_json(&request) { let read_request: Vec<Vec<String>> = match read_json(&request) {
Some(v) => v, Some(v) => v,
None => return rouille::Response::empty_400(), None => return rouille::Response::empty_400(),
@@ -188,8 +177,6 @@ pub fn start(config: Config, project: Project, vfs: Arc<Mutex<Vfs>>) {
}, },
(POST) (/write) => { (POST) (/write) => {
let _plugin_chain = PLUGIN_CHAIN.lock().unwrap();
let _write_request: Vec<WriteSpecifier> = match read_json(&request) { let _write_request: Vec<WriteSpecifier> = match read_json(&request) {
Some(v) => v, Some(v) => v,
None => return rouille::Response::empty_400(), None => return rouille::Response::empty_400(),