Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple cookies in azure #4716

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions packages/qwik-city/middleware/azure-swa/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
import type { AzureFunction, Context, HttpRequest } from '@azure/functions';
import { setServerPlatform } from '@builder.io/qwik/server';
import {
mergeHeadersCookies,
requestHandler,
} from '@builder.io/qwik-city/middleware/request-handler';
import { requestHandler } from '@builder.io/qwik-city/middleware/request-handler';
import type {
ServerRenderOptions,
ServerRequestEvent,
} from '@builder.io/qwik-city/middleware/request-handler';
import { getNotFound } from '@qwik-city-not-found-paths';
import { _deserializeData, _serializeData, _verifySerializable } from '@builder.io/qwik';
import { parseString } from 'set-cookie-parser';

// @builder.io/qwik-city/middleware/azure-swa

interface AzureResponse {
status: number;
headers: { [key: string]: any };
body?: string | Uint8Array;
cookies?: AzureCookie[];
}

interface AzureCookie {
/** Cookie name */
name: string;
/** Cookie value */
value: string;
/** Specifies allowed hosts to receive the cookie */
domain?: string;
/** Specifies URL path that must exist in the requested URL */
path?: string;
/**
* NOTE: It is generally recommended that you use maxAge over expires.
* Sets the cookie to expire at a specific date instead of when the client closes.
* This can be a Javascript Date or Unix time in milliseconds.
*/
expires?: Date | number;
/** Sets the cookie to only be sent with an encrypted request */
secure?: boolean;
/** Sets the cookie to be inaccessible to JavaScript's Document.cookie API */
httpOnly?: boolean;
/** Can restrict the cookie to not be sent with cross-site requests */
sameSite?: string | undefined;
/** Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. */
maxAge?: number;
}

/**
Expand Down Expand Up @@ -56,10 +80,9 @@ export function createQwikCity(opts: QwikCityAzureOptions): AzureFunction {
status,
body: new Uint8Array(),
headers: {},
cookies: cookies.headers().map((header) => parseString(header)),
};
mergeHeadersCookies(headers, cookies).forEach(
(value, key) => (response.headers[key] = value)
);
headers.forEach((value, key) => (response.headers[key] = value));
return new WritableStream({
write(chunk: Uint8Array) {
if (response.body instanceof Uint8Array) {
Expand Down
2 changes: 2 additions & 0 deletions packages/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@types/mdast": "^3.0.11",
"@types/node": "^20.3.3",
"@types/refractor": "3.0.2",
"@types/set-cookie-parser": "^2.4.2",
"estree-util-value-to-estree": "3.0.1",
"github-slugger": "2.0.0",
"hast-util-heading-rank": "2.1.1",
Expand All @@ -113,6 +114,7 @@
"rehype-autolink-headings": "6.1.1",
"remark-frontmatter": "4.0.1",
"remark-gfm": "3.0.1",
"set-cookie-parser": "^2.6.0",
"tsm": "2.3.0",
"typescript": "5.1.6",
"unified": "10.1.2",
Expand Down
64 changes: 35 additions & 29 deletions pnpm-lock.yaml

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