Skip to content

Commit

Permalink
feat: add ipx imageProxy to Hono
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Jul 26, 2024
1 parent 247483c commit 7e74e36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { updateJob } from "./jobs/cron-update.js"
import bookmark from "./routes/bookmark/index.js"
import feed from "./routes/feed/index.js"
import root from "./routes/root.js"
import { ipxHandler } from "./lib/imageProxy.js"

const limiter = rateLimiter({
windowMs: 1 * 60 * 1000, // 5 minutes
Expand All @@ -26,6 +27,7 @@ const app = new Hono<{ Bindings: HttpBindings }>({ strict: false }).basePath(
app.use(logger())
app.use(prettyJSON())
app.use(limiter)
app.use("/img", c => ipxHandler(c.req.raw))

app.route("/bookmark", bookmark)
app.route("/feed", feed)
Expand Down
17 changes: 17 additions & 0 deletions apps/backend/src/lib/imageProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
createIPX,
createIPXWebServer,
ipxFSStorage,
ipxHttpStorage,
} from 'ipx';

const ipx = createIPX({
storage: ipxFSStorage({ dir: './public/' }),
httpStorage: ipxHttpStorage({
domains: ['images.unsplash.com']
}),
});

export const ipxHandler = createIPXWebServer(ipx)

// const app = new Hono().use('/', (c) => createIPXWebServer(ipx)(c.req.raw));

0 comments on commit 7e74e36

Please sign in to comment.