mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 22:25:26 +00:00
server: Make 'rojo serve' respect --port option
This commit is contained in:
@@ -55,15 +55,37 @@ fn main() {
|
|||||||
let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or("."));
|
let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or("."));
|
||||||
let full_path = make_path_absolute(project_path);
|
let full_path = make_path_absolute(project_path);
|
||||||
|
|
||||||
librojo::commands::init(&full_path);
|
commands::init(&full_path);
|
||||||
},
|
},
|
||||||
("serve", Some(sub_matches)) => {
|
("serve", Some(sub_matches)) => {
|
||||||
let project_path = match sub_matches.value_of("PROJECT") {
|
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
||||||
Some(v) => make_path_absolute(Path::new(v)),
|
Some(v) => make_path_absolute(Path::new(v)),
|
||||||
None => std::env::current_dir().unwrap(),
|
None => std::env::current_dir().unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
librojo::commands::serve(&project_path);
|
let port = match sub_matches.value_of("port") {
|
||||||
|
Some(v) => match v.parse::<u16>() {
|
||||||
|
Ok(port) => port,
|
||||||
|
Err(_) => {
|
||||||
|
error!("Invalid port {}", v);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = commands::ServeOptions {
|
||||||
|
fuzzy_project_path,
|
||||||
|
port,
|
||||||
|
};
|
||||||
|
|
||||||
|
match commands::serve(&options) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("{}", e);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
("build", Some(sub_matches)) => {
|
("build", Some(sub_matches)) => {
|
||||||
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
||||||
|
|||||||
@@ -1,36 +1,54 @@
|
|||||||
use std::{
|
use std::{
|
||||||
path::Path,
|
path::PathBuf,
|
||||||
process,
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use failure::Fail;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
project::Project,
|
project::{Project, ProjectLoadFuzzyError},
|
||||||
web::Server,
|
web::Server,
|
||||||
session::Session,
|
session::Session,
|
||||||
// roblox_studio,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn serve(fuzzy_project_location: &Path) {
|
const DEFAULT_PORT: u16 = 34872;
|
||||||
info!("Looking for project at {}", fuzzy_project_location.display());
|
|
||||||
|
|
||||||
let project = match Project::load_fuzzy(fuzzy_project_location) {
|
#[derive(Debug)]
|
||||||
Ok(project) => project,
|
pub struct ServeOptions {
|
||||||
Err(error) => {
|
pub fuzzy_project_path: PathBuf,
|
||||||
error!("{}", error);
|
pub port: Option<u16>,
|
||||||
process::exit(1);
|
}
|
||||||
},
|
|
||||||
};
|
#[derive(Debug, Fail)]
|
||||||
|
pub enum ServeError {
|
||||||
|
#[fail(display = "Project load error: {}", _0)]
|
||||||
|
ProjectLoadError(#[fail(cause)] ProjectLoadFuzzyError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ProjectLoadFuzzyError> for ServeError {
|
||||||
|
fn from(error: ProjectLoadFuzzyError) -> ServeError {
|
||||||
|
ServeError::ProjectLoadError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
|
||||||
|
info!("Looking for project at {}", options.fuzzy_project_path.display());
|
||||||
|
|
||||||
|
let project = Project::load_fuzzy(&options.fuzzy_project_path)?;
|
||||||
|
|
||||||
info!("Found project at {}", project.file_location.display());
|
info!("Found project at {}", project.file_location.display());
|
||||||
info!("Using project {:#?}", project);
|
info!("Using project {:#?}", project);
|
||||||
|
|
||||||
// roblox_studio::install_bundled_plugin().unwrap();
|
|
||||||
|
|
||||||
let session = Arc::new(Session::new(project).unwrap());
|
let session = Arc::new(Session::new(project).unwrap());
|
||||||
let server = Server::new(Arc::clone(&session));
|
let server = Server::new(Arc::clone(&session));
|
||||||
|
|
||||||
println!("Server listening on port 34872");
|
let port = options.port
|
||||||
|
// .or(project.serve_port)
|
||||||
|
.unwrap_or(DEFAULT_PORT);
|
||||||
|
|
||||||
server.listen(34872);
|
println!("Rojo server listening on port {}", port);
|
||||||
|
|
||||||
|
server.listen(port);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ impl Server {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listen(self, port: u64) {
|
pub fn listen(self, port: u16) {
|
||||||
let address = format!("0.0.0.0:{}", port);
|
let address = format!("0.0.0.0:{}", port);
|
||||||
|
|
||||||
rouille::start_server(address, move |request| self.handle_request(request));
|
rouille::start_server(address, move |request| self.handle_request(request));
|
||||||
|
|||||||
Reference in New Issue
Block a user