Ship swagger files and mount them on /swagger

This commit is contained in:
Antoine Gersant 2019-04-07 18:54:53 -07:00
parent a4578194f0
commit 32a808b962
4 changed files with 25 additions and 7 deletions

View file

@ -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')

View file

@ -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"

View file

@ -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,7 +224,7 @@ 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");
@ -231,8 +232,19 @@ fn run() -> Result<()> {
.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,
)?;

View file

@ -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()))
}