Skip to content

Commit

Permalink
feat: add CDN cache (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored Oct 18, 2022
1 parent 2989a46 commit 9ddf0fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@ipld/dag-json": "^8.0.11",
"@ipld/dag-pb": "^2.1.18",
"@web3-storage/fast-unixfs-exporter": "^0.2.0",
"@web3-storage/gateway-lib": "^1.2.0",
"@web3-storage/gateway-lib": "^1.3.0",
"cardex": "^0.0.0",
"chardet": "^1.5.0",
"dagula": "^4.1.0",
Expand Down
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
withContentDispositionHeader,
withErrorHandler,
withHttpGet,
withCdnCache,
withParsedIpfsUrl,
composeMiddleware
} from '@web3-storage/gateway-lib/middleware'
Expand All @@ -26,6 +27,7 @@ export default {
fetch (request, env, ctx) {
console.log(request.method, request.url)
const middleware = composeMiddleware(
withCdnCache,
withCorsHeaders,
withContentDispositionHeader,
withErrorHandler,
Expand All @@ -42,10 +44,6 @@ export default {
/** @type {import('@web3-storage/gateway-lib').Handler<DagulaContext & CarCidsContext & IpfsUrlContext, Environment>} */
async function handler (request, env, ctx) {
const { headers } = request
if (headers.get('Cache-Control') === 'only-if-cached') {
return new Response(null, { status: 412 })
}

const { searchParams } = ctx
if (!searchParams) throw new Error('missing URL search params')

Expand Down

0 comments on commit 9ddf0fa

Please sign in to comment.