-
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.
Added a feature to the backend to avoid building the backend if a fea…
…ture is specified
- Loading branch information
1 parent
15cdf8d
commit 0053c64
Showing
3 changed files
with
52 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ authors = ["TylerBloom <[email protected]>"] | |
|
||
[features] | ||
db-tests = [] | ||
ignore-frontend = [] | ||
|
||
[dependencies] | ||
# In-House deps | ||
|
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,30 +1,52 @@ | ||
use axum::response::{Html, Response}; | ||
use http::{header, HeaderMap, HeaderValue, StatusCode}; | ||
use hyper::{body::Bytes, Body}; | ||
#[allow(clippy::wildcard_imports)] | ||
pub use frontend::*; | ||
|
||
const INDEX_HTML: &str = include_str!("../../assets/index.html"); | ||
const APP_WASM: &[u8] = include_bytes!("../../assets/squire_web_bg.wasm"); | ||
const APP_JS: &str = include_str!("../../assets/squire_web.js"); | ||
#[cfg(feature = "ignore-frontend")] | ||
mod frontend { | ||
use axum::response::Html; | ||
|
||
pub async fn landing() -> Html<&'static str> { | ||
Html(INDEX_HTML) | ||
} | ||
pub async fn landing() -> Html<&'static str> { | ||
Html("Frontend not compiled...") | ||
} | ||
|
||
pub async fn get_wasm() -> Response<Body> { | ||
let bytes = Bytes::copy_from_slice(APP_WASM); | ||
let body: Body = bytes.into(); | ||
pub async fn get_wasm() {} | ||
|
||
Response::builder() | ||
.header(header::CONTENT_TYPE, "application/wasm") | ||
.body(body) | ||
.unwrap() | ||
pub async fn get_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) | ||
#[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, Response}; | ||
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"); | ||
const APP_JS: &str = include_str!("../../assets/squire_web.js"); | ||
|
||
pub async fn landing() -> Html<&'static str> { | ||
Html(INDEX_HTML) | ||
} | ||
|
||
pub async fn get_wasm() -> Response<Body> { | ||
let bytes = Bytes::copy_from_slice(APP_WASM); | ||
let body: Body = bytes.into(); | ||
|
||
Response::builder() | ||
.header(header::CONTENT_TYPE, "application/wasm") | ||
.body(body) | ||
.unwrap() | ||
} | ||
|
||
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) | ||
} | ||
} |