diff --git a/packages/esm-worker/package-lock.json b/packages/esm-worker/package-lock.json index ac2161c33..e7c1b9089 100644 --- a/packages/esm-worker/package-lock.json +++ b/packages/esm-worker/package-lock.json @@ -1,12 +1,12 @@ { "name": "esm-worker", - "version": "0.120.0", + "version": "0.120.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "esm-worker", - "version": "0.120.0", + "version": "0.120.1", "license": "MIT", "devDependencies": { "@cloudflare/workers-types": "4.20230419.0", diff --git a/packages/esm-worker/package.json b/packages/esm-worker/package.json index b300365c2..48de17a92 100644 --- a/packages/esm-worker/package.json +++ b/packages/esm-worker/package.json @@ -1,7 +1,7 @@ { "name": "esm-worker", "description": "A Cloudflare workers that handles all requests to the esm.sh origin server at the edge.", - "version": "0.120.0", + "version": "0.120.1", "type": "module", "module": "dist/index.js", "types": "types/index.d.ts", diff --git a/packages/esm-worker/src/index.ts b/packages/esm-worker/src/index.ts index 5d0ade450..655912bc4 100644 --- a/packages/esm-worker/src/index.ts +++ b/packages/esm-worker/src/index.ts @@ -130,7 +130,11 @@ class ESMWorker { } } - if (pathname === "/" || pathname.startsWith("/embed/")) { + if ( + pathname === "/" || + pathname === "/build" || + pathname.startsWith("/embed/") + ) { return fetchServerOrigin( req, ctx, @@ -408,13 +412,18 @@ class ESMWorker { const ua = req.headers.get("user-agent"); target = getEsmaVersionFromUA(ua); } - headers.set("Cache-Control", "public, max-age=31536000, immutable"); + const pined = hasBuildVerPrefix || hasBuildVerQuery; + if (pined) { + headers.set("Cache-Control", "public, max-age=31536000, immutable"); + } else { + headers.set("Cache-Control", "public, max-age=86400"); + } return redirect( new URL( `${prefix}/${pkg}@${packageVersion}/${target}/${packageName}.css`, url, ), - 301, + pined ? 301 : 302, headers, ); } diff --git a/server/server_handler.go b/server/server_handler.go index c4d2c04b2..038e3f074 100644 --- a/server/server_handler.go +++ b/server/server_handler.go @@ -1104,7 +1104,11 @@ func esmHandler() rex.Handle { return rex.Status(404, "Package CSS not found") } url := fmt.Sprintf("%s%s/%s.css", cdnOrigin, cfg.BasePath, strings.TrimSuffix(taskID, path.Ext(taskID))) - return rex.Redirect(url, http.StatusMovedPermanently) + code := 302 + if isPined { + code = 301 + } + return rex.Redirect(url, code) } if isBarePath {