mirror of
https://github.com/ParkerTenBroeck/hdl_sim.git
synced 2026-06-07 05:28:45 -04:00
packaged binary
This commit is contained in:
parent
0289d1171f
commit
defbd88adf
11 changed files with 110 additions and 24 deletions
|
|
@ -1,29 +1,60 @@
|
|||
use axum::{
|
||||
Router,
|
||||
extract::ws::WebSocketUpgrade,
|
||||
http::{StatusCode, header},
|
||||
response::{Html, IntoResponse},
|
||||
routing::get,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::SocketAddr;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
pub mod build;
|
||||
pub mod run;
|
||||
pub mod local;
|
||||
pub mod remote;
|
||||
|
||||
const UI_INDEX_HTML: &str = include_str!("../ui/index.html");
|
||||
const UI_STYLES_CSS: &str = include_str!("../ui/styles.css");
|
||||
const UI_APP_JS: &str = include_str!("../ui/app.js");
|
||||
|
||||
async fn serve_index() -> impl IntoResponse {
|
||||
Html(UI_INDEX_HTML)
|
||||
}
|
||||
|
||||
async fn serve_styles() -> impl IntoResponse {
|
||||
(
|
||||
[(header::CONTENT_TYPE, "text/css; charset=utf-8")],
|
||||
UI_STYLES_CSS,
|
||||
)
|
||||
}
|
||||
|
||||
async fn serve_app_js() -> impl IntoResponse {
|
||||
(
|
||||
[(header::CONTENT_TYPE, "application/javascript; charset=utf-8")],
|
||||
UI_APP_JS,
|
||||
)
|
||||
}
|
||||
|
||||
async fn not_found() -> impl IntoResponse {
|
||||
(StatusCode::NOT_FOUND, "not found")
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.route(
|
||||
"/ws/local",
|
||||
get(|ws: WebSocketUpgrade| async move { ws.on_upgrade(remote::ws_handler) }),
|
||||
)
|
||||
.route("/", get(serve_index))
|
||||
.route("/index.html", get(serve_index))
|
||||
.route("/styles.css", get(serve_styles))
|
||||
.route("/app.js", get(serve_app_js))
|
||||
.route(
|
||||
"/ws/remote",
|
||||
get(|ws: WebSocketUpgrade| async move { ws.on_upgrade(local::ws_handler) }),
|
||||
)
|
||||
.fallback_service(ServeDir::new("ui"));
|
||||
.route(
|
||||
"/ws/local",
|
||||
get(|ws: WebSocketUpgrade| async move { ws.on_upgrade(remote::ws_handler) }),
|
||||
)
|
||||
.fallback(get(not_found));
|
||||
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
println!("Open UI: http://{}/", addr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue