mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Convert most web code to use Project where possible
This commit is contained in:
parent
bfda025a97
commit
473edad399
4 changed files with 31 additions and 16 deletions
|
|
@ -5,10 +5,10 @@ use std::fs;
|
||||||
use rand;
|
use rand;
|
||||||
|
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use web;
|
use web::{self, WebConfig};
|
||||||
use session::Session;
|
use session::Session;
|
||||||
|
|
||||||
pub fn serve(project_path: &PathBuf, port: Option<u64>) {
|
pub fn serve(project_path: &PathBuf, override_port: Option<u64>) {
|
||||||
let server_id = rand::random::<u64>();
|
let server_id = rand::random::<u64>();
|
||||||
|
|
||||||
let project = match Project::load(project_path) {
|
let project = match Project::load(project_path) {
|
||||||
|
|
@ -22,20 +22,16 @@ pub fn serve(project_path: &PathBuf, port: Option<u64>) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let port = override_port.unwrap_or(project.serve_port);
|
||||||
|
|
||||||
println!("Using project {:#?}", project);
|
println!("Using project {:#?}", project);
|
||||||
|
|
||||||
let mut session = Session::new(project.clone());
|
let mut session = Session::new(project.clone());
|
||||||
session.start();
|
session.start();
|
||||||
|
|
||||||
let web_config = web::WebConfig {
|
let web_config = WebConfig::from_session(server_id, port, &session);
|
||||||
port: port.unwrap_or(project.serve_port),
|
|
||||||
server_id,
|
|
||||||
rbx_session: session.get_rbx_session(),
|
|
||||||
message_session: session.get_message_session(),
|
|
||||||
partitions: project.partitions,
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("Server listening on port {}", web_config.port);
|
println!("Server listening on port {}", port);
|
||||||
|
|
||||||
web::start(web_config);
|
web::start(web_config);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ trait Middleware {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
project: Project,
|
pub project: Project,
|
||||||
vfs_session: Arc<RwLock<VfsSession>>,
|
vfs_session: Arc<RwLock<VfsSession>>,
|
||||||
rbx_session: Arc<RwLock<RbxSession>>,
|
rbx_session: Arc<RwLock<RbxSession>>,
|
||||||
message_session: MessageSession,
|
message_session: MessageSession,
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,33 @@ use std::sync::{mpsc, RwLock, Arc};
|
||||||
|
|
||||||
use rouille::{self, Request, Response};
|
use rouille::{self, Request, Response};
|
||||||
|
|
||||||
use web_util::read_json;
|
|
||||||
use id::Id;
|
use id::Id;
|
||||||
|
use message_session::{MessageSession, Message};
|
||||||
|
use project::Project;
|
||||||
use rbx::RbxInstance;
|
use rbx::RbxInstance;
|
||||||
use rbx_session::RbxSession;
|
use rbx_session::RbxSession;
|
||||||
use message_session::{MessageSession, Message};
|
use session::Session;
|
||||||
use partition::Partition;
|
use web_util::read_json;
|
||||||
|
|
||||||
/// The set of configuration the web server needs to start.
|
/// The set of configuration the web server needs to start.
|
||||||
pub struct WebConfig {
|
pub struct WebConfig {
|
||||||
pub port: u64,
|
pub port: u64,
|
||||||
|
pub project: Project,
|
||||||
pub server_id: u64,
|
pub server_id: u64,
|
||||||
pub rbx_session: Arc<RwLock<RbxSession>>,
|
pub rbx_session: Arc<RwLock<RbxSession>>,
|
||||||
pub message_session: MessageSession,
|
pub message_session: MessageSession,
|
||||||
pub partitions: HashMap<String, Partition>,
|
}
|
||||||
|
|
||||||
|
impl WebConfig {
|
||||||
|
pub fn from_session(server_id: u64, port: u64, session: &Session) -> WebConfig {
|
||||||
|
WebConfig {
|
||||||
|
port,
|
||||||
|
server_id,
|
||||||
|
project: session.project.clone(),
|
||||||
|
rbx_session: session.get_rbx_session(),
|
||||||
|
message_session: session.get_message_session(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
@ -78,7 +91,7 @@ impl Server {
|
||||||
|
|
||||||
let mut partitions = HashMap::new();
|
let mut partitions = HashMap::new();
|
||||||
|
|
||||||
for partition in self.config.partitions.values() {
|
for partition in self.config.project.partitions.values() {
|
||||||
partitions.insert(partition.name.clone(), partition.target.as_slice());
|
partitions.insert(partition.name.clone(), partition.target.as_slice());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
|
extern crate rouille;
|
||||||
|
|
||||||
extern crate librojo;
|
extern crate librojo;
|
||||||
|
|
||||||
|
use rouille::{Request, Response};
|
||||||
|
|
||||||
|
use librojo::web::{Server, WebConfig};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue