-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the development flow for the frontend
- Loading branch information
1 parent
07fb70e
commit e73e454
Showing
6 changed files
with
82 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,43 @@ | ||
#[allow(clippy::wildcard_imports)] | ||
pub use frontend::*; | ||
|
||
#[cfg(feature = "ignore-frontend")] | ||
mod frontend { | ||
use axum::response::Html; | ||
|
||
pub async fn landing() -> Html<&'static str> { | ||
Html("Frontend not compiled...") | ||
} | ||
|
||
pub async fn get_wasm() {} | ||
|
||
pub async fn get_js() {} | ||
use axum::{ | ||
response::{Html, Response}, | ||
routing::get, | ||
Check failure on line 3 in squire_core/src/assets.rs
|
||
Router, | ||
}; | ||
use crate::state::AppState; | ||
use http::{header, HeaderMap, HeaderValue, StatusCode}; | ||
use hyper::{body::Bytes, Body}; | ||
|
||
const INDEX_HTML: &str = include_str!("../../assets/index.html"); | ||
const APP_WASM: &[u8] = include_bytes!("../../assets/squire_web_bg.wasm.gz"); | ||
const APP_JS: &str = include_str!("../../assets/squire_web.js"); | ||
|
||
pub fn inject_ui(router: Router<AppState>) -> Router<AppState> { | ||
router | ||
.route("/", get(landing)) | ||
.route("/squire_web_bg.wasm", get(get_wasm)) | ||
.route("/squire_web.js", get(get_js)) | ||
.fallback(landing) | ||
} | ||
|
||
#[cfg(all(feature = "ignore-frontend", not(debug_assertions)))] | ||
compile_error!("In release mode, you must compile the frontend!"); | ||
|
||
#[cfg(not(feature = "ignore-frontend"))] | ||
mod frontend { | ||
use axum::response::Html; | ||
use http::{header, HeaderMap, HeaderValue}; | ||
|
||
const INDEX_HTML: &str = include_str!("../../assets/index.html"); | ||
const APP_WASM: &'static [u8] = include_bytes!("../../assets/squire_web_bg.wasm.gz"); | ||
const APP_JS: &str = include_str!("../../assets/squire_web.js"); | ||
|
||
pub async fn landing() -> Html<&'static str> { | ||
Html(INDEX_HTML) | ||
} | ||
pub async fn landing() -> Html<&'static str> { | ||
Html(INDEX_HTML) | ||
} | ||
|
||
pub async fn get_wasm() -> (HeaderMap, &'static [u8]) { | ||
let mut headers = HeaderMap::with_capacity(2); | ||
headers.insert(header::CONTENT_ENCODING, HeaderValue::from_static("gzip")); // Unzips the compressed file | ||
headers.insert( | ||
header::CONTENT_TYPE, | ||
HeaderValue::from_static("application/wasm"), | ||
); | ||
(headers, APP_WASM) | ||
} | ||
pub async fn get_wasm() -> (HeaderMap, &'static [u8]) { | ||
let mut headers = HeaderMap::with_capacity(2); | ||
headers.insert(header::CONTENT_ENCODING, HeaderValue::from_static("gzip")); // Unzips the compressed file | ||
headers.insert( | ||
header::CONTENT_TYPE, | ||
HeaderValue::from_static("application/wasm"), | ||
); | ||
(headers, APP_WASM) | ||
} | ||
|
||
pub async fn get_js() -> (HeaderMap, &'static str) { | ||
let mut headers = HeaderMap::with_capacity(1); | ||
headers.insert( | ||
header::CONTENT_TYPE, | ||
HeaderValue::from_static("application/javascript;charset=utf-8"), | ||
); | ||
(headers, APP_JS) | ||
} | ||
pub async fn get_js() -> (StatusCode, HeaderMap, &'static str) { | ||
let mut headers = HeaderMap::with_capacity(1); | ||
headers.insert( | ||
header::CONTENT_TYPE, | ||
HeaderValue::from_static("application/javascript;charset=utf-8"), | ||
); | ||
(StatusCode::OK, headers, APP_JS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters