-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1611b68
commit 5c7051d
Showing
12 changed files
with
72 additions
and
3 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
Test text |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::collections::HashMap; | ||
|
||
use once_cell::sync::Lazy; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(module = "__STATIC_CONTENT_MANIFEST")] | ||
extern "C" { | ||
#[wasm_bindgen(js_name = "default")] | ||
static MANIFEST_STR: String; | ||
} | ||
|
||
pub static ASSET_MANIFEST: Lazy<HashMap<&str, &str>> = | ||
Lazy::new(|| serde_json::from_str(&MANIFEST_STR).unwrap_or_default()); |
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,22 @@ | ||
use crate::request::Request; | ||
use crate::response::Response; | ||
use crate::{Headers, Result, RouteContext}; | ||
use worker_sys::ASSET_MANIFEST; | ||
|
||
const ASSET_NAMESPACE: &str = "__STATIC_CONTENT"; | ||
|
||
pub async fn get_asset_from_kv<D>(req: Request, ctx: RouteContext<D>) -> Result<Response> { | ||
let url = req.url()?; | ||
let path = &url.path()[1..]; | ||
let mime = mime_guess::from_path(path).first_or_octet_stream(); | ||
|
||
let key = ASSET_MANIFEST.get(path).unwrap_or(&path); | ||
let bytes = ctx.kv(ASSET_NAMESPACE)?.get(key).bytes().await?; | ||
if let Some(bytes) = bytes { | ||
let mut headers = Headers::new(); | ||
headers.set("content_type", &mime.to_string())?; | ||
return Ok(Response::from_bytes(bytes)?.with_headers(headers)); | ||
} | ||
|
||
Response::error("Not found", 404) | ||
} |
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