From 3b593366017dfff770ca9809bcde5aac3a8f5d3d Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 18 Oct 2022 11:48:16 +0100 Subject: [PATCH] feat: add CDN cache --- package-lock.json | 14 +++++++------- package.json | 2 +- src/index.js | 6 ++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2c6b033..afb26b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,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", @@ -2571,9 +2571,9 @@ } }, "node_modules/@web3-storage/gateway-lib": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@web3-storage/gateway-lib/-/gateway-lib-1.2.0.tgz", - "integrity": "sha512-OnxX3scyrpjnD4iIyfpG9fmA1V60/QQw5LbzqKWQo+ZsXRLxW/J1wPU7rkWQL6qalNzhhwh92dpaZLw6YW/qYA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@web3-storage/gateway-lib/-/gateway-lib-1.3.0.tgz", + "integrity": "sha512-slSba8q86c7BikQxPJS/TEMJZHoaxPKgy9dfgCMiWvT4zQRBK33GDMjw5cf+2sbuUqQzB+g7R3rnABcMzZtIIw==", "dependencies": { "@ipld/car": "^4.1.5", "@web3-storage/handlebars": "^1.0.0", @@ -13033,9 +13033,9 @@ } }, "@web3-storage/gateway-lib": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@web3-storage/gateway-lib/-/gateway-lib-1.2.0.tgz", - "integrity": "sha512-OnxX3scyrpjnD4iIyfpG9fmA1V60/QQw5LbzqKWQo+ZsXRLxW/J1wPU7rkWQL6qalNzhhwh92dpaZLw6YW/qYA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@web3-storage/gateway-lib/-/gateway-lib-1.3.0.tgz", + "integrity": "sha512-slSba8q86c7BikQxPJS/TEMJZHoaxPKgy9dfgCMiWvT4zQRBK33GDMjw5cf+2sbuUqQzB+g7R3rnABcMzZtIIw==", "requires": { "@ipld/car": "^4.1.5", "@web3-storage/handlebars": "^1.0.0", diff --git a/package.json b/package.json index c130e6b..1e4ba65 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index b3bb004..abaf240 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ import { withContentDispositionHeader, withErrorHandler, withHttpGet, + withCdnCache, withParsedIpfsUrl, composeMiddleware } from '@web3-storage/gateway-lib/middleware' @@ -26,6 +27,7 @@ export default { fetch (request, env, ctx) { console.log(request.method, request.url) const middleware = composeMiddleware( + withCdnCache, withCorsHeaders, withContentDispositionHeader, withErrorHandler, @@ -42,10 +44,6 @@ export default { /** @type {import('@web3-storage/gateway-lib').Handler} */ 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')