Skip to content

Commit c0bf606

Browse files
committed
chore: update miniflare to get new assets functionality
1 parent 25f9fd0 commit c0bf606

File tree

6 files changed

+62
-40
lines changed

6 files changed

+62
-40
lines changed

package-lock.json

Lines changed: 33 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@types/node": "^20.4.8",
1818
"@types/uuid": "^9.0.2",
19-
"miniflare": "^3.20240909.4",
19+
"miniflare": "^3.20241205.0",
2020
"typescript": "^5.1.6",
2121
"undici": "^5.28.4",
2222
"uuid": "^9.0.0",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/* Modules */
2828
"module": "ES2022", /* Specify what module code is generated. */
2929
// "rootDir": "./", /* Specify the root folder within your source files. */
30-
"moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
30+
"moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
3131
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */

worker-sandbox/src/assets.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
1+
use worker::Url;
2+
13
#[cfg(not(feature = "http"))]
24
pub async fn handle_asset(
35
req: worker::Request,
46
env: worker::Env,
57
_data: crate::SomeSharedData,
68
) -> worker::Result<worker::Response> {
7-
use worker::Url;
9+
let url: Url = req.url()?;
10+
let name: String = url.path_segments().unwrap().nth(1).unwrap().to_string();
11+
let url: String = ["https://dummyurl.com/", &name].concat();
12+
13+
env.assets("ASSETS")
14+
.expect("ASSETS BINDING")
15+
.fetch(url, None)
16+
.await
17+
}
18+
19+
#[cfg(feature = "http")]
20+
#[worker::send]
21+
pub async fn handle_asset(
22+
req: worker::Request,
23+
env: worker::Env,
24+
_data: crate::SomeSharedData,
25+
) -> worker::Result<worker::Response> {
26+
use std::convert::TryInto;
827

928
let url: Url = req.url()?;
1029
let name: String = url.path_segments().unwrap().nth(1).unwrap().to_string();
1130
let url: String = ["https://dummyurl.com/", &name].concat();
12-
Ok(env
13-
.assets("ASSETS")
31+
32+
env.assets("ASSETS")
1433
.expect("ASSETS BINDING")
1534
.fetch(url, None)
16-
.await?)
35+
.await?
36+
.try_into()
1737
}

worker-sandbox/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn make_router(data: SomeSharedData, env: Env) -> axum::Router {
6464
"/async-request",
6565
get(handler!(request::handle_async_request)),
6666
)
67+
.route("/asset/:name", get(handler!(assets::handle_asset)))
6768
.route("/websocket", get(handler!(ws::handle_websocket)))
6869
.route("/got-close-event", get(handler!(handle_close_event)))
6970
.route("/ws-client", get(handler!(ws::handle_websocket_client)))

worker-sandbox/tests/mf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export const mf = new Miniflare({
7373
queueProducers: ["my_queue", "my_queue"],
7474
fetchMock: mockAgent,
7575
assets: {
76-
path: "./public",
77-
bindingName: "ASSETS",
76+
directory: "./public",
77+
binding: "ASSETS",
7878
routingConfig: {
7979
has_user_worker: true,
8080
},

0 commit comments

Comments
 (0)