Skip to content

Commit 80ee957

Browse files
committed
Remove remix-hon dependency
Removes `remix-hon` as a dependency to allow for a smoother upgrade to react-router 7
1 parent cddd29e commit 80ee957

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

package-lock.json

Lines changed: 1 addition & 2 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@
7373
},
7474
"dependencies": {
7575
"@hono/vite-dev-server": "^0.17.0",
76-
"@remix-run/server-runtime": "^2.15.0",
77-
"remix-hono": "^0.0.16"
76+
"@remix-run/server-runtime": "^2.15.0"
7877
},
7978
"peerDependencies": {
8079
"hono": "*"

src/handlers/cloudflare-pages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Hono } from 'hono'
22
import { handle } from 'hono/cloudflare-pages'
3-
import { staticAssets } from 'remix-hono/cloudflare'
4-
import { remix } from '../middleware'
3+
import { remix, staticAssets } from '../middleware'
54
import { defaultGetLoadContext } from '../remix'
65
import type { GetLoadContext } from '../remix'
76

src/middleware.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,45 @@ export const remix = ({ mode, build, getLoadContext }: RemixMiddlewareOptions) =
2222
)
2323
})
2424
}
25+
26+
27+
/**
28+
* A string of directives for the Cache-Control header.
29+
* See the [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) docs for more information.
30+
*/
31+
32+
type CacheControl= string;
33+
34+
interface StaticAssetsOptions {
35+
cache?: CacheControl;
36+
}
37+
38+
export function staticAssets(options: StaticAssetsOptions = {}) {
39+
return createMiddleware(async (c, next) => {
40+
let binding = c.env?.ASSETS as Fetcher | undefined;
41+
42+
if (!binding) throw new ReferenceError("The binding ASSETS is not set.");
43+
44+
let response: Response;
45+
46+
c.req.raw.headers.delete("if-none-match");
47+
48+
try {
49+
response = await binding.fetch(c.req.url, c.req.raw.clone());
50+
51+
// If the request failed, we just call the next middleware
52+
if (response.status >= 400) return await next();
53+
54+
response = new Response(response.body, response);
55+
56+
// If cache options are configured, we set the cache-control header
57+
if (options.cache) {
58+
response.headers.set("cache-control", );
59+
}
60+
61+
return response;
62+
} catch {
63+
return await next();
64+
}
65+
});
66+
}

0 commit comments

Comments
 (0)