Skip to content

Commit

Permalink
refactor(vercel-edge): set cookie base url
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed Apr 22, 2024
1 parent 36f2029 commit a303f0c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/qwik-city/middleware/vercel-edge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { setServerPlatform } from '@builder.io/qwik/server';
// @builder.io/qwik-city/middleware/vercel-edge
const COUNTRY_HEADER_NAME = 'x-vercel-ip-country';
const IP_HEADER_NAME = 'x-real-ip';
const VERCEL_COOKIE = '__vdpl';
const VERCEL_SKEW_PROTECTION_ENABLED = 'VERCEL_SKEW_PROTECTION_ENABLED';
const VERCEL_DEPLOYMENT_ID = 'VERCEL_DEPLOYMENT_ID';
const BASE_URL = 'BASE_URL';

/** @public */
export function createQwikCity(opts: QwikCityVercelEdgeOptions) {
Expand Down Expand Up @@ -56,13 +58,12 @@ export function createQwikCity(opts: QwikCityVercelEdgeOptions) {
const { readable, writable } = new TransformStream();
if (serverRequestEv.env.get(VERCEL_SKEW_PROTECTION_ENABLED)) {
const deploymentId = serverRequestEv.env.get(VERCEL_DEPLOYMENT_ID) || '';
// TODO: make configurable
const basePathname = '/';
const baseUrl = serverRequestEv.env.get(BASE_URL) || '/';
// only on document request
if (request.headers.has('Sec-Fetch-Dest')) {
// set cookie before creating response
cookies.set('__vdpl', deploymentId, {
path: basePathname,
cookies.set(VERCEL_COOKIE, deploymentId, {
path: baseUrl,
secure: true,
sameSite: true,
httpOnly: true,
Expand Down

0 comments on commit a303f0c

Please sign in to comment.