Skip to content

Commit 6b5866c

Browse files
authored
fix: Remove remix-hono dependency (#36)
* Remove remix-hon dependency Removes `remix-hon` as a dependency to allow for a smoother upgrade to react-router 7 * fix formatting * Remove remix-hono from examples
1 parent cddd29e commit 6b5866c

File tree

6 files changed

+54
-73
lines changed

6 files changed

+54
-73
lines changed

examples/cloudflare-pages/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"hono": "^4.5.11",
2020
"isbot": "^4.1.0",
2121
"react": "^18.3.1",
22-
"react-dom": "^18.3.1",
23-
"remix-hono": "^0.0.16"
22+
"react-dom": "^18.3.1"
2423
},
2524
"devDependencies": {
2625
"@hono/vite-dev-server": "^0.16.0",
@@ -37,4 +36,4 @@
3736
"engines": {
3837
"node": ">=20.0.0"
3938
}
40-
}
39+
}

examples/cloudflare-workers/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"hono": "^4.6.9",
2020
"isbot": "^4.1.0",
2121
"react": "^18.2.0",
22-
"react-dom": "^18.2.0",
23-
"remix-hono": "^0.0.16"
22+
"react-dom": "^18.2.0"
2423
},
2524
"devDependencies": {
2625
"@hono/vite-dev-server": "^0.16.0",
@@ -37,4 +36,4 @@
3736
"engines": {
3837
"node": ">=20.0.0"
3938
}
40-
}
39+
}

package-lock.json

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

0 commit comments

Comments
 (0)