Skip to content

Commit

Permalink
fix(cloudflare): drop set-cookie-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
oleghalin authored and Hebilicious committed Jul 2, 2023
1 parent 4712c73 commit 5632f49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"semver": "^7.5.3",
"serve-placeholder": "^2.0.1",
"serve-static": "^1.15.0",
"set-cookie-parser": "^2.5.1",
"source-map-support": "^0.5.21",
"std-env": "^3.3.3",
"ufo": "^1.1.2",
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

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

16 changes: 10 additions & 6 deletions src/runtime/entries/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
mapRequestToAsset,
} from "@cloudflare/kv-asset-handler";
import { withLeadingSlash, withoutBase, withoutTrailingSlash } from "ufo";
import { splitCookiesString } from "set-cookie-parser";
import { splitCookiesString } from "h3";
import { requestHasBody } from "../utils";
import { nitroApp } from "#internal/nitro/app";
import { useRuntimeConfig } from "#internal/nitro";
Expand All @@ -25,10 +25,14 @@ async function handleEvent(event: FetchEvent) {

// Fetch public assets from KV only
if (isPublicAssetURL(id)) {
return await getAssetFromKV(event, {
cacheControl: assetsCacheControl,
mapRequestToAsset: baseURLModifier,
});
try {
return await getAssetFromKV(event, {
cacheControl: assetsCacheControl,
mapRequestToAsset: baseURLModifier,
});
} catch (e) {
return new Response(e.message || e.toString(), { status: 404 });
}
}

let body;
Expand Down Expand Up @@ -85,7 +89,7 @@ function normalizeOutgoingHeaders(

for (const [k, v] of Object.entries(headers)) {
if (k === "set-cookie") {
for (const cookie of splitCookiesString(v)) {
for (const cookie of splitCookiesString(Array.isArray(v) ? v.join(',') : v)) {
result.append("set-cookie", cookie);
}

Expand Down

0 comments on commit 5632f49

Please sign in to comment.