forked from rojo-rbx/rojo
server: Make 'rojo serve' respect --port option
This commit is contained in:
@@ -1,36 +1,54 @@
|
||||
use std::{
|
||||
path::Path,
|
||||
process,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use failure::Fail;
|
||||
|
||||
use crate::{
|
||||
project::Project,
|
||||
project::{Project, ProjectLoadFuzzyError},
|
||||
web::Server,
|
||||
session::Session,
|
||||
// roblox_studio,
|
||||
};
|
||||
|
||||
pub fn serve(fuzzy_project_location: &Path) {
|
||||
info!("Looking for project at {}", fuzzy_project_location.display());
|
||||
const DEFAULT_PORT: u16 = 34872;
|
||||
|
||||
let project = match Project::load_fuzzy(fuzzy_project_location) {
|
||||
Ok(project) => project,
|
||||
Err(error) => {
|
||||
error!("{}", error);
|
||||
process::exit(1);
|
||||
},
|
||||
};
|
||||
#[derive(Debug)]
|
||||
pub struct ServeOptions {
|
||||
pub fuzzy_project_path: PathBuf,
|
||||
pub port: Option<u16>,
|
||||
}
|
||||
|
||||
#[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!("Using project {:#?}", project);
|
||||
|
||||
// roblox_studio::install_bundled_plugin().unwrap();
|
||||
|
||||
let session = Arc::new(Session::new(project).unwrap());
|
||||
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(())
|
||||
}
|
||||
Reference in New Issue
Block a user