-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Nemesis-AS/feat-embed-static
Added Static Asset Bundling
- Loading branch information
Showing
12 changed files
with
169 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[config] | ||
rootdir = D:\Music\Test |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pub mod api; | ||
pub mod views; | ||
|
||
use actix_web::web::{scope, ServiceConfig}; | ||
|
||
use api::register as register_api; | ||
use views::register as register_views; | ||
|
||
pub fn register(config: &mut ServiceConfig) { | ||
config.service(scope("/api/v1").configure(register_api)); | ||
config.service(scope("").configure(register_views)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::utils::static_resolver::handle_embedded_file; | ||
use actix_web::{ | ||
get, | ||
web::{Path, ServiceConfig}, | ||
HttpResponse, Responder, | ||
}; | ||
|
||
// View Routes | ||
#[get("/")] | ||
pub async fn index() -> HttpResponse { | ||
handle_embedded_file("index.html") | ||
} | ||
|
||
#[get("/dist/{_:.*}")] | ||
pub async fn dist(path: Path<String>) -> impl Responder { | ||
handle_embedded_file(path.as_str()) | ||
} | ||
|
||
pub fn register(config: &mut ServiceConfig) { | ||
config.service(index).service(dist); | ||
} |
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,3 +1,5 @@ | ||
pub mod static_resolver; | ||
|
||
use std::{fs, path::PathBuf}; | ||
|
||
use crate::metadata; | ||
|
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::Asset; | ||
use actix_web::HttpResponse; | ||
use mime_guess::from_path; | ||
|
||
pub fn handle_embedded_file(path: &str) -> HttpResponse { | ||
match Asset::get(path) { | ||
Some(content) => HttpResponse::Ok() | ||
.content_type(from_path(path).first_or_octet_stream().as_ref()) | ||
.body(content.data.into_owned()), | ||
None => HttpResponse::NotFound().body("404 Not Found"), | ||
} | ||
} |
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