Commit 445ad0fa89d7d58a6f0962fe1bb4c757f02f80d8
1 parent
88cfb041
Set content-type when sending javascript or wasm code
Showing
4 changed files
with
23 additions
and
1 deletions
@@ -12,6 +12,8 @@ mod upload_worker; | @@ -12,6 +12,8 @@ mod upload_worker; | ||
12 | use models::image::Image; | 12 | use models::image::Image; |
13 | use routes::markdown::*; | 13 | use routes::markdown::*; |
14 | use routes::other::*; | 14 | use routes::other::*; |
15 | +use routes::ui::frontend_js; | ||
16 | +use routes::ui::frontend_wasm; | ||
15 | use routes::user::*; | 17 | use routes::user::*; |
16 | use routes::upload::*; | 18 | use routes::upload::*; |
17 | use routes::image::*; | 19 | use routes::image::*; |
@@ -78,6 +80,12 @@ async fn main() -> std::io::Result<()> { | @@ -78,6 +80,12 @@ async fn main() -> std::io::Result<()> { | ||
78 | . route(web::put().to(update_user)) | 80 | . route(web::put().to(update_user)) |
79 | ) | 81 | ) |
80 | ) | 82 | ) |
83 | + . service( web::scope("/ui") | ||
84 | + . route( "/artshop_frontend.js" | ||
85 | + , web::get().to(frontend_js) ) | ||
86 | + . route( "/artshop_frontend_bg.wasm" | ||
87 | + , web::get().to(frontend_wasm)) | ||
88 | + ) | ||
81 | . service( web::scope("") | 89 | . service( web::scope("") |
82 | . route("/", web::get().to(root)) | 90 | . route("/", web::get().to(root)) |
83 | . route("/api.html", web::get().to(apidoc)) | 91 | . route("/api.html", web::get().to(apidoc)) |
server/src/routes/ui.rs
0 → 100644
1 | +use actix_web::Error; | ||
2 | +use actix_files::NamedFile; | ||
3 | +use anyhow::Result; | ||
4 | + | ||
5 | +pub async fn frontend_js() -> Result<NamedFile, Error> { | ||
6 | + Ok( NamedFile::open("static/ui/artshop_frontend.js")? | ||
7 | + . set_content_type(mime::APPLICATION_JAVASCRIPT) ) | ||
8 | +} | ||
9 | + | ||
10 | +pub async fn frontend_wasm() -> Result<NamedFile, Error> { | ||
11 | + Ok( NamedFile::open("static/ui/artshop_frontend_bg.wasm")? | ||
12 | + . set_content_type("application/wasm".parse::<mime::Mime>().unwrap()) ) | ||
13 | +} |
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | </head> | 7 | </head> |
8 | <body> | 8 | <body> |
9 | <script type="module"> | 9 | <script type="module"> |
10 | - import init from '/static/ui/artshop_frontend.js'; | 10 | + import init from '/ui/artshop_frontend.js'; |
11 | window.addEventListener('load', async () => { | 11 | window.addEventListener('load', async () => { |
12 | await init(); | 12 | await init(); |
13 | }); | 13 | }); |
Please
register
or
login
to post a comment