Skip to content
Permalink
Browse files

Ship swagger files and mount them on /swagger

  • Loading branch information...
agersant committed Apr 8, 2019
1 parent a457819 commit 32a808b9624caf027c0ab5074bb746c9d2bb1e92
Showing with 25 additions and 7 deletions.
  1. +1 −1 build_release_unix.sh
  2. +1 −0 build_release_windows.ps1
  3. +18 −4 src/main.rs
  4. +5 −2 src/server.rs
@@ -3,7 +3,7 @@ echo "Creating output directory"
mkdir -p release/tmp

echo "Copying package files"
cp -r web src migrations Cargo.toml Cargo.lock res/unix/Makefile release/tmp
cp -r web docs/swagger src migrations Cargo.toml Cargo.lock res/unix/Makefile release/tmp

echo "Creating tarball"
POLARIS_VERSION=$(grep -m 1 ^version Cargo.toml | awk '{print $3}' | tr -d '"\r\n')
@@ -29,6 +29,7 @@ Copy-Item .\web\style .\release\tmp\web\style -recurse
Copy-Item .\web\tags .\release\tmp\web\tags -recurse
Copy-Item .\web\favicon.png .\release\tmp\web\
Copy-Item .\web\index.html .\release\tmp\web\
Copy-Item .\docs\swagger .\release\tmp\swagger -recurse

""
"Creating installer"
@@ -149,6 +149,7 @@ fn run() -> Result<()> {
options.optopt("p", "port", "set polaris to run on a custom port", "PORT");
options.optopt("d", "database", "set the path to index database", "FILE");
options.optopt("w", "web", "set the path to web client files", "DIRECTORY");
options.optopt("s", "swagger", "set the path to swagger files", "DIRECTORY");
options.optopt(
"l",
"log",
@@ -223,16 +224,27 @@ fn run() -> Result<()> {
let api_url = format!("{}/api", &prefix_url);
info!("Mounting API on {}", api_url);

// Static files mount target
// Web client mount target
let web_dir_name = matches.opt_str("w");
let mut default_web_dir = utils::get_data_root()?;
default_web_dir.push("web");
let web_dir_path = web_dir_name
.map(|n| Path::new(n.as_str()).to_path_buf())
.unwrap_or(default_web_dir);
info!("Static files location is {}", web_dir_path.display());
let static_url = format!("/{}", &prefix_url);
info!("Mounting static files on {}", static_url);
let web_url = format!("/{}", &prefix_url);
info!("Mounting web client files on {}", web_url);

// Swagger files mount target
let swagger_dir_name = matches.opt_str("s");
let mut default_swagger_dir = utils::get_data_root()?;
default_swagger_dir.push("swagger");
let swagger_dir_path = swagger_dir_name
.map(|n| Path::new(n.as_str()).to_path_buf())
.unwrap_or(default_swagger_dir);
info!("Swagger files location is {}", swagger_dir_path.display());
let swagger_url = format!("/{}swagger", &prefix_url);
info!("Mounting swagger files on {}", swagger_url);

// Start server
info!("Starting up server");
@@ -244,9 +256,11 @@ fn run() -> Result<()> {

let server = server::get_server(
port,
&static_url,
&api_url,
&web_url,
&web_dir_path,
&swagger_url,
&swagger_dir_path,
db.clone(),
command_sender,
)?;
@@ -10,9 +10,11 @@ use crate::index::CommandSender;

pub fn get_server(
port: u16,
static_url: &str,
api_url: &str,
web_url: &str,
web_dir_path: &PathBuf,
swagger_url: &str,
swagger_dir_path: &PathBuf,
db: Arc<DB>,
command_sender: Arc<CommandSender>,
) -> Result<rocket::Rocket, errors::Error> {
@@ -23,6 +25,7 @@ pub fn get_server(
Ok(rocket::custom(config)
.manage(db)
.manage(command_sender)
.mount(&static_url, StaticFiles::from(web_dir_path))
.mount(&swagger_url, StaticFiles::from(swagger_dir_path))
.mount(&web_url, StaticFiles::from(web_dir_path))
.mount(&api_url, api::get_routes()))
}

0 comments on commit 32a808b

Please sign in to comment.
You can’t perform that action at this time.