Skip to content

Fixed Transit UI #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions example_apps/transit/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl UiConfig {
pub fn ui_server_router(port: u16) -> Router {
Router::new()
.route("/index.html", get(index_html))
.route("/dist/main/swimos-transit.js", get(transit_js))
.route("/dist/main/swimos-transit.js.map", get(transit_js_map))
.route("/dist/main/swim-transit.js", get(transit_js))
.route("/dist/main/swim-transit.js.map", get(transit_js_map))
.with_state(UiConfig { port })
}

Expand All @@ -49,7 +49,7 @@ const INDEX: &str = "ui/index.html";
async fn index_html(State(UiConfig { port }): State<UiConfig>) -> impl IntoResponse {
if let Ok(file) = File::open(INDEX).await {
let lines = LinesStream::new(BufReader::new(file).lines()).map_ok(move |mut line| {
if line == "const portParam = baseUri.port();" {
if line.contains("const portParam = baseUri.port();") {
format!("const portParam = {};\n", port)
} else {
line.push('\n');
Expand Down Expand Up @@ -78,15 +78,15 @@ async fn index_html(State(UiConfig { port }): State<UiConfig>) -> impl IntoRespo

async fn transit_js() -> impl IntoResponse {
let headers = [(header::CONTENT_TYPE, JS.clone())];
(headers, load_file("dist/main/swimos-transit.js").await)
(headers, load_file("dist/main/swim-transit.js").await)
}

static HTML: HeaderValue = HeaderValue::from_static("text/html; charset=utf-8");
static JS: HeaderValue = HeaderValue::from_static("application/json");

async fn transit_js_map() -> impl IntoResponse {
let headers = [(header::CONTENT_TYPE, JS.clone())];
(headers, load_file("dist/main/swimos-transit.js.map").await)
(headers, load_file("dist/main/swim-transit.js.map").await)
}

async fn load_file(path: &str) -> impl IntoResponse {
Expand Down
Loading