Properly redirect to index.html so relative src properties in html work
This commit is contained in:
parent
c3b75e6058
commit
26a894c0b1
1 changed files with 17 additions and 5 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
use rocket::http::uri::Origin;
|
||||||
use rocket::response::NamedFile;
|
use rocket::response::NamedFile;
|
||||||
|
use rocket::response::Redirect;
|
||||||
use rocket::State;
|
use rocket::State;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -14,10 +16,9 @@ pub fn get_routes() -> Vec<rocket::Route> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/", rank = 9)]
|
#[get("/", rank = 9)]
|
||||||
fn index(static_dirs: State<Arc<StaticDirs>>) -> io::Result<NamedFile> {
|
fn index(origin: &Origin) -> Redirect {
|
||||||
let mut path = static_dirs.swagger_dir_path.clone();
|
let redirect = Redirect::permanent(origin.path().to_owned() + "index.html");
|
||||||
path.push("index.html");
|
return redirect;
|
||||||
NamedFile::open(path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<file..>", rank = 9)]
|
#[get("/<file..>", rank = 9)]
|
||||||
|
@ -26,6 +27,17 @@ fn files(static_dirs: State<Arc<StaticDirs>>, file: PathBuf) -> Option<NamedFile
|
||||||
NamedFile::open(path).ok()
|
NamedFile::open(path).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_index_redirect() {
|
||||||
|
use rocket::http::Status;
|
||||||
|
use crate::test::get_test_environment;
|
||||||
|
|
||||||
|
let env = get_test_environment("swagger_index_redirect.sqlite");
|
||||||
|
let client = &env.client;
|
||||||
|
let response = client.get("/swagger").dispatch();
|
||||||
|
assert_eq!(response.status(), Status::PermanentRedirect);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_index() {
|
fn test_index() {
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
@ -33,6 +45,6 @@ fn test_index() {
|
||||||
|
|
||||||
let env = get_test_environment("swagger_index.sqlite");
|
let env = get_test_environment("swagger_index.sqlite");
|
||||||
let client = &env.client;
|
let client = &env.client;
|
||||||
let response = client.get("/swagger").dispatch();
|
let response = client.get("/swagger/index.html").dispatch();
|
||||||
assert_eq!(response.status(), Status::Ok);
|
assert_eq!(response.status(), Status::Ok);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue