From 55a1b5bb58a07cbf6d86818c28c199751bde03b5 Mon Sep 17 00:00:00 2001 From: matthewp Date: Wed, 28 Sep 2022 20:57:35 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/@types/astro.ts | 4 +- packages/astro/src/core/app/index.ts | 2 +- packages/astro/src/core/cookies/cookies.ts | 76 +++++++++---------- packages/astro/src/core/cookies/index.ts | 11 +-- packages/astro/src/core/cookies/response.ts | 8 +- packages/astro/src/core/endpoint/index.ts | 4 +- packages/astro/src/core/render/core.ts | 4 +- packages/astro/src/core/render/result.ts | 2 +- .../src/vite-plugin-astro-server/index.ts | 4 +- packages/astro/test/astro-cookies.test.js | 36 ++++----- .../astro/test/units/cookies/delete.test.js | 14 ++-- packages/astro/test/units/cookies/get.test.js | 36 ++++----- packages/astro/test/units/cookies/has.test.js | 4 +- packages/astro/test/units/cookies/set.test.js | 8 +- .../cloudflare/src/server.advanced.ts | 4 +- .../cloudflare/src/server.directory.ts | 4 +- packages/integrations/deno/src/server.ts | 8 +- .../integrations/image/src/loaders/squoosh.ts | 7 +- .../netlify/src/netlify-edge-functions.ts | 4 +- .../netlify/src/netlify-functions.ts | 4 +- packages/integrations/node/src/server.ts | 4 +- .../vercel/src/edge/entrypoint.ts | 4 +- .../src/serverless/request-transform.ts | 12 ++- 23 files changed, 127 insertions(+), 137 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 7c19dcca6..5cafa45f4 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -14,8 +14,8 @@ import type * as vite from 'vite'; import type { z } from 'zod'; import type { SerializedSSRManifest } from '../core/app/types'; import type { PageBuildData } from '../core/build/types'; -import type { AstroCookies } from '../core/cookies'; import type { AstroConfigSchema } from '../core/config'; +import type { AstroCookies } from '../core/cookies'; import type { ViteConfigWithSSR } from '../core/create-vite'; import type { AstroComponentFactory, Metadata } from '../runtime/server'; export type { @@ -120,7 +120,7 @@ export interface AstroGlobal extends AstroGlobalPartial { /** * Utility for getting and setting cookies values. */ - cookies: AstroCookies, + cookies: AstroCookies; url: URL; /** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) * diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index ce3422738..d4197839f 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -9,6 +9,7 @@ import type { LogOptions } from '../logger/core.js'; import type { RouteInfo, SSRManifest as Manifest } from './types'; import mime from 'mime'; +import { getSetCookiesFromResponse } from '../cookies/index.js'; import { call as callEndpoint } from '../endpoint/index.js'; import { consoleLogDestination } from '../logger/console.js'; import { error } from '../logger/core.js'; @@ -21,7 +22,6 @@ import { } from '../render/ssr-element.js'; import { matchRoute } from '../routing/match.js'; export { deserializeManifest } from './common.js'; -import { getSetCookiesFromResponse } from '../cookies/index.js'; export const pagesVirtualModuleId = '@astrojs-pages-virtual-entry'; export const resolvedPagesVirtualModuleId = '\0' + pagesVirtualModuleId; diff --git a/packages/astro/src/core/cookies/cookies.ts b/packages/astro/src/core/cookies/cookies.ts index 7f530ce85..3345024d7 100644 --- a/packages/astro/src/core/cookies/cookies.ts +++ b/packages/astro/src/core/cookies/cookies.ts @@ -2,13 +2,13 @@ import type { CookieSerializeOptions } from 'cookie'; import { parse, serialize } from 'cookie'; interface AstroCookieSetOptions { - domain?: string; - expires?: Date; - httpOnly?: boolean; - maxAge?: number; - path?: string; - sameSite?: boolean | 'lax' | 'none' | 'strict'; - secure?: boolean; + domain?: string; + expires?: Date; + httpOnly?: boolean; + maxAge?: number; + path?: string; + sameSite?: boolean | 'lax' | 'none' | 'strict'; + secure?: boolean; } interface AstroCookieDeleteOptions { @@ -16,17 +16,17 @@ interface AstroCookieDeleteOptions { } interface AstroCookieInterface { - value: string | undefined; - json(): Record; - number(): number; + value: string | undefined; + json(): Record; + number(): number; boolean(): boolean; } interface AstroCookiesInterface { - get(key: string): AstroCookieInterface; + get(key: string): AstroCookieInterface; has(key: string): boolean; - set(key: string, value: string | Record, options?: AstroCookieSetOptions): void; - delete(key: string, options?: AstroCookieDeleteOptions): void; + set(key: string, value: string | Record, options?: AstroCookieSetOptions): void; + delete(key: string, options?: AstroCookieDeleteOptions): void; } const DELETED_EXPIRATION = new Date(0); @@ -35,7 +35,7 @@ const DELETED_VALUE = 'deleted'; class AstroCookie implements AstroCookieInterface { constructor(public value: string | undefined) {} json() { - if(this.value === undefined) { + if (this.value === undefined) { throw new Error(`Cannot convert undefined to an object.`); } return JSON.parse(this.value); @@ -44,8 +44,8 @@ class AstroCookie implements AstroCookieInterface { return Number(this.value); } boolean() { - if(this.value === 'false') return false; - if(this.value === '0') return false; + if (this.value === 'false') return false; + if (this.value === '0') return false; return Boolean(this.value); } } @@ -68,10 +68,10 @@ class AstroCookies implements AstroCookiesInterface { */ delete(key: string, options?: AstroCookieDeleteOptions): void { const serializeOptions: CookieSerializeOptions = { - expires: DELETED_EXPIRATION + expires: DELETED_EXPIRATION, }; - if(options?.path) { + if (options?.path) { serializeOptions.path = options.path; } @@ -79,7 +79,7 @@ class AstroCookies implements AstroCookiesInterface { this.#ensureOutgoingMap().set(key, [ DELETED_VALUE, serialize(key, DELETED_VALUE, serializeOptions), - false + false, ]); } @@ -92,9 +92,9 @@ class AstroCookies implements AstroCookiesInterface { */ get(key: string): AstroCookie { // Check for outgoing Set-Cookie values first - if(this.#outgoing !== null && this.#outgoing.has(key)) { - let [serializedValue,, isSetValue] = this.#outgoing.get(key)!; - if(isSetValue) { + if (this.#outgoing !== null && this.#outgoing.has(key)) { + let [serializedValue, , isSetValue] = this.#outgoing.get(key)!; + if (isSetValue) { return new AstroCookie(serializedValue); } else { return new AstroCookie(undefined); @@ -110,11 +110,11 @@ class AstroCookies implements AstroCookiesInterface { * Astro.cookies.has(key) returns a boolean indicating whether this cookie is either * part of the initial request or set via Astro.cookies.set(key) * @param key The cookie to check for. - * @returns + * @returns */ has(key: string): boolean { - if(this.#outgoing !== null && this.#outgoing.has(key)) { - let [,,isSetValue] = this.#outgoing.get(key)!; + if (this.#outgoing !== null && this.#outgoing.has(key)) { + let [, , isSetValue] = this.#outgoing.get(key)!; return isSetValue; } const values = this.#ensureParsed(); @@ -132,13 +132,13 @@ class AstroCookies implements AstroCookiesInterface { */ set(key: string, value: string | Record, options?: AstroCookieSetOptions): void { let serializedValue: string; - if(typeof value === 'string') { + if (typeof value === 'string') { serializedValue = value; } else { // Support stringifying JSON objects for convenience. First check that this is // a plain object and if it is, stringify. If not, allow support for toString() overrides. let toStringValue = value.toString(); - if(toStringValue === Object.prototype.toString.call(value)) { + if (toStringValue === Object.prototype.toString.call(value)) { serializedValue = JSON.stringify(value); } else { serializedValue = toStringValue; @@ -146,14 +146,14 @@ class AstroCookies implements AstroCookiesInterface { } const serializeOptions: CookieSerializeOptions = {}; - if(options) { + if (options) { Object.assign(serializeOptions, options); } this.#ensureOutgoingMap().set(key, [ serializedValue, serialize(key, serializedValue, serializeOptions), - true + true, ]); } @@ -161,27 +161,27 @@ class AstroCookies implements AstroCookiesInterface { * Astro.cookies.header() returns an iterator for the cookies that have previously * been set by either Astro.cookies.set() or Astro.cookies.delete(). * This method is primarily used by adapters to set the header on outgoing responses. - * @returns + * @returns */ *headers(): Generator { - if(this.#outgoing == null) return; - for(const [,value] of this.#outgoing) { + if (this.#outgoing == null) return; + for (const [, value] of this.#outgoing) { yield value[1]; } } #ensureParsed(): Record { - if(!this.#requestValues) { + if (!this.#requestValues) { this.#parse(); } - if(!this.#requestValues) { + if (!this.#requestValues) { this.#requestValues = {}; } return this.#requestValues; } #ensureOutgoingMap(): Map { - if(!this.#outgoing) { + if (!this.#outgoing) { this.#outgoing = new Map(); } return this.#outgoing; @@ -189,7 +189,7 @@ class AstroCookies implements AstroCookiesInterface { #parse() { const raw = this.#request.headers.get('cookie'); - if(!raw) { + if (!raw) { return; } @@ -197,6 +197,4 @@ class AstroCookies implements AstroCookiesInterface { } } -export { - AstroCookies -}; +export { AstroCookies }; diff --git a/packages/astro/src/core/cookies/index.ts b/packages/astro/src/core/cookies/index.ts index 18dc3ebca..1b0c6b7a0 100644 --- a/packages/astro/src/core/cookies/index.ts +++ b/packages/astro/src/core/cookies/index.ts @@ -1,9 +1,2 @@ - -export { - AstroCookies -} from './cookies.js'; - -export { - attachToResponse, - getSetCookiesFromResponse -} from './response.js'; +export { AstroCookies } from './cookies.js'; +export { attachToResponse, getSetCookiesFromResponse } from './response.js'; diff --git a/packages/astro/src/core/cookies/response.ts b/packages/astro/src/core/cookies/response.ts index 0e52ac8cb..d04ce1ef3 100644 --- a/packages/astro/src/core/cookies/response.ts +++ b/packages/astro/src/core/cookies/response.ts @@ -8,19 +8,19 @@ export function attachToResponse(response: Response, cookies: AstroCookies) { function getFromResponse(response: Response): AstroCookies | undefined { let cookies = Reflect.get(response, astroCookiesSymbol); - if(cookies != null) { + if (cookies != null) { return cookies as AstroCookies; } else { return undefined; } } -export function * getSetCookiesFromResponse(response: Response): Generator { +export function* getSetCookiesFromResponse(response: Response): Generator { const cookies = getFromResponse(response); - if(!cookies) { + if (!cookies) { return; } - for(const headerValue of cookies.headers()) { + for (const headerValue of cookies.headers()) { yield headerValue; } } diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index 75e451e6f..9f1adb655 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -1,8 +1,8 @@ import type { APIContext, EndpointHandler, Params } from '../../@types/astro'; import type { RenderOptions } from '../render/core'; -import { AstroCookies, attachToResponse } from '../cookies/index.js'; import { renderEndpoint } from '../../runtime/server/index.js'; +import { AstroCookies, attachToResponse } from '../cookies/index.js'; import { getParamsAndProps, GetParamsAndPropsError } from '../render/core.js'; export type EndpointOptions = Pick< @@ -34,7 +34,7 @@ function createAPIContext(request: Request, params: Params): APIContext { return { cookies: new AstroCookies(request), request, - params + params, }; } diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index 7e5fe1f96..bbbb6c53f 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -10,8 +10,8 @@ import type { } from '../../@types/astro'; import type { LogOptions } from '../logger/core.js'; -import { attachToResponse } from '../cookies/index.js'; import { Fragment, renderPage } from '../../runtime/server/index.js'; +import { attachToResponse } from '../cookies/index.js'; import { getParams } from '../routing/params.js'; import { createResult } from './result.js'; import { callGetStaticPaths, findPathItemByKey, RouteCache } from './route-cache.js'; @@ -169,7 +169,7 @@ export async function render(opts: RenderOptions): Promise { // If there is an Astro.cookies instance, attach it to the response so that // adapters can grab the Set-Cookie headers. - if(result.cookies) { + if (result.cookies) { attachToResponse(response, result.cookies); } diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index c0e650a8f..f6bb57ed7 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -177,7 +177,7 @@ export function createResult(args: CreateResultArgs): SSRResult { return Reflect.get(request, clientAddressSymbol); }, get cookies() { - if(cookies) { + if (cookies) { return cookies; } cookies = new AstroCookies(request); diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index e976280c8..5fbce100a 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -5,8 +5,8 @@ import type { AstroSettings, ManifestData } from '../@types/astro'; import type { SSROptions } from '../core/render/dev/index'; import { Readable } from 'stream'; -import { call as callEndpoint } from '../core/endpoint/dev/index.js'; import { getSetCookiesFromResponse } from '../core/cookies/index.js'; +import { call as callEndpoint } from '../core/endpoint/dev/index.js'; import { collectErrorMetadata, ErrorWithMetadata, @@ -65,7 +65,7 @@ async function writeWebResponse(res: http.ServerResponse, webResponse: Response) // Attach any set-cookie headers added via Astro.cookies.set() const setCookieHeaders = Array.from(getSetCookiesFromResponse(webResponse)); - if(setCookieHeaders.length) { + if (setCookieHeaders.length) { res.setHeader('Set-Cookie', setCookieHeaders); } res.writeHead(status, _headers); diff --git a/packages/astro/test/astro-cookies.test.js b/packages/astro/test/astro-cookies.test.js index ece374d82..77e2cd2ba 100644 --- a/packages/astro/test/astro-cookies.test.js +++ b/packages/astro/test/astro-cookies.test.js @@ -30,19 +30,19 @@ describe('Astro.cookies', () => { it('is able to get cookies from the request', async () => { const response = await fixture.fetch('/get-json', { headers: { - cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}` - } + cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, + }, }); expect(response.status).to.equal(200); const html = await response.text(); - + const $ = cheerio.load(html); expect($('dd').text()).to.equal('light'); }); - + it('can set the cookie value', async () => { const response = await fixture.fetch('/set-value', { - method: 'POST' + method: 'POST', }); expect(response.status).to.equal(200); expect(response.headers.has('set-cookie')).to.equal(true); @@ -61,35 +61,35 @@ describe('Astro.cookies', () => { const response = await app.render(request); return response; } - + it('is able to get cookies from the request', async () => { const response = await fetchResponse('/get-json', { headers: { - cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}` - } + cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, + }, }); expect(response.status).to.equal(200); const html = await response.text(); - + const $ = cheerio.load(html); expect($('dd').text()).to.equal('light'); }); - + it('can set the cookie value', async () => { const response = await fetchResponse('/set-value', { - method: 'POST' + method: 'POST', }); expect(response.status).to.equal(200); let headers = Array.from(app.setCookieHeaders(response)); expect(headers).to.have.a.lengthOf(1); expect(headers[0]).to.match(/Expires/); }); - + it('Early returning a Response still includes set headers', async () => { const response = await fetchResponse('/early-return', { headers: { - cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}` - } + cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, + }, }); expect(response.status).to.equal(302); let headers = Array.from(app.setCookieHeaders(response)); @@ -99,13 +99,13 @@ describe('Astro.cookies', () => { expect(data).to.be.an('object'); expect(data.mode).to.equal('dark'); }); - + it('API route can get and set cookies', async () => { const response = await fetchResponse('/set-prefs', { method: 'POST', headers: { - cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}` - } + cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, + }, }); expect(response.status).to.equal(302); let headers = Array.from(app.setCookieHeaders(response)); @@ -115,5 +115,5 @@ describe('Astro.cookies', () => { expect(data).to.be.an('object'); expect(data.mode).to.equal('dark'); }); - }) + }); }); diff --git a/packages/astro/test/units/cookies/delete.test.js b/packages/astro/test/units/cookies/delete.test.js index e049995d4..571a3e40d 100644 --- a/packages/astro/test/units/cookies/delete.test.js +++ b/packages/astro/test/units/cookies/delete.test.js @@ -9,8 +9,8 @@ describe('astro/src/core/cookies', () => { it('creates a Set-Cookie header to delete it', () => { let req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); expect(cookies.get('foo').value).to.equal('bar'); @@ -23,8 +23,8 @@ describe('astro/src/core/cookies', () => { it('calling cookies.get() after returns undefined', () => { let req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); expect(cookies.get('foo').value).to.equal('bar'); @@ -36,8 +36,8 @@ describe('astro/src/core/cookies', () => { it('calling cookies.has() after returns false', () => { let req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); expect(cookies.has('foo')).to.equal(true); @@ -50,7 +50,7 @@ describe('astro/src/core/cookies', () => { let req = new Request('http://example.com/'); let cookies = new AstroCookies(req); cookies.delete('foo', { - path: '/subpath/' + path: '/subpath/', }); let headers = Array.from(cookies.headers()); expect(headers).to.have.a.lengthOf(1); diff --git a/packages/astro/test/units/cookies/get.test.js b/packages/astro/test/units/cookies/get.test.js index 837c2075e..f044d715a 100644 --- a/packages/astro/test/units/cookies/get.test.js +++ b/packages/astro/test/units/cookies/get.test.js @@ -9,8 +9,8 @@ describe('astro/src/core/cookies', () => { it('gets the cookie value', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); const cookies = new AstroCookies(req); expect(cookies.get('foo').value).to.equal('bar'); @@ -20,8 +20,8 @@ describe('astro/src/core/cookies', () => { it('returns a JavaScript object', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=%7B%22key%22%3A%22value%22%7D' - } + cookie: 'foo=%7B%22key%22%3A%22value%22%7D', + }, }); let cookies = new AstroCookies(req); @@ -42,8 +42,8 @@ describe('astro/src/core/cookies', () => { it('Coerces into a number', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=22' - } + cookie: 'foo=22', + }, }); let cookies = new AstroCookies(req); @@ -55,8 +55,8 @@ describe('astro/src/core/cookies', () => { it('Coerces non-number into NaN', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); @@ -70,8 +70,8 @@ describe('astro/src/core/cookies', () => { it('Coerces true into `true`', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=true' - } + cookie: 'foo=true', + }, }); let cookies = new AstroCookies(req); @@ -83,8 +83,8 @@ describe('astro/src/core/cookies', () => { it('Coerces false into `false`', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=false' - } + cookie: 'foo=false', + }, }); let cookies = new AstroCookies(req); @@ -96,8 +96,8 @@ describe('astro/src/core/cookies', () => { it('Coerces 1 into `true`', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=1' - } + cookie: 'foo=1', + }, }); let cookies = new AstroCookies(req); @@ -109,8 +109,8 @@ describe('astro/src/core/cookies', () => { it('Coerces 0 into `false`', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=0' - } + cookie: 'foo=0', + }, }); let cookies = new AstroCookies(req); @@ -122,8 +122,8 @@ describe('astro/src/core/cookies', () => { it('Coerces truthy strings into `true`', () => { const req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); diff --git a/packages/astro/test/units/cookies/has.test.js b/packages/astro/test/units/cookies/has.test.js index d9a7eb66f..c4cb4776a 100644 --- a/packages/astro/test/units/cookies/has.test.js +++ b/packages/astro/test/units/cookies/has.test.js @@ -9,8 +9,8 @@ describe('astro/src/core/cookies', () => { it('returns true if the request has the cookie', () => { let req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); expect(cookies.has('foo')).to.equal(true); diff --git a/packages/astro/test/units/cookies/set.test.js b/packages/astro/test/units/cookies/set.test.js index acf436766..a70f2f457 100644 --- a/packages/astro/test/units/cookies/set.test.js +++ b/packages/astro/test/units/cookies/set.test.js @@ -20,7 +20,7 @@ describe('astro/src/core/cookies', () => { let cookies = new AstroCookies(req); cookies.set('foo', 'bar', { httpOnly: true, - path: '/subpath/' + path: '/subpath/', }); let headers = Array.from(cookies.headers()); expect(headers).to.have.a.lengthOf(1); @@ -68,12 +68,12 @@ describe('astro/src/core/cookies', () => { it('Overrides a value in the request', () => { let req = new Request('http://example.com/', { headers: { - 'cookie': 'foo=bar' - } + cookie: 'foo=bar', + }, }); let cookies = new AstroCookies(req); expect(cookies.get('foo').value).to.equal('bar'); - + // Set a new value cookies.set('foo', 'baz'); expect(cookies.get('foo').value).to.equal('baz'); diff --git a/packages/integrations/cloudflare/src/server.advanced.ts b/packages/integrations/cloudflare/src/server.advanced.ts index 62adb44ec..c285ccaba 100644 --- a/packages/integrations/cloudflare/src/server.advanced.ts +++ b/packages/integrations/cloudflare/src/server.advanced.ts @@ -28,8 +28,8 @@ export function createExports(manifest: SSRManifest) { ); let response = await app.render(request, routeData); - if(app.setCookieHeaders) { - for(const setCookieHeader of app.setCookieHeaders(response)) { + if (app.setCookieHeaders) { + for (const setCookieHeader of app.setCookieHeaders(response)) { response.headers.append('Set-Cookie', setCookieHeader); } } diff --git a/packages/integrations/cloudflare/src/server.directory.ts b/packages/integrations/cloudflare/src/server.directory.ts index 7a484378c..e51d0ea57 100644 --- a/packages/integrations/cloudflare/src/server.directory.ts +++ b/packages/integrations/cloudflare/src/server.directory.ts @@ -30,8 +30,8 @@ export function createExports(manifest: SSRManifest) { ); let response = await app.render(request, routeData); - if(app.setCookieHeaders) { - for(const setCookieHeader of app.setCookieHeaders(response)) { + if (app.setCookieHeaders) { + for (const setCookieHeader of app.setCookieHeaders(response)) { response.headers.append('Set-Cookie', setCookieHeader); } } diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index d8c6aede9..453d73c40 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -27,8 +27,8 @@ export function start(manifest: SSRManifest, options: Options) { let ip = connInfo?.remoteAddr?.hostname; Reflect.set(request, Symbol.for('astro.clientAddress'), ip); const response = await app.render(request); - if(app.setCookieHeaders) { - for(const setCookieHeader of app.setCookieHeaders(response)) { + if (app.setCookieHeaders) { + for (const setCookieHeader of app.setCookieHeaders(response)) { response.headers.append('Set-Cookie', setCookieHeader); } } @@ -46,8 +46,8 @@ export function start(manifest: SSRManifest, options: Options) { // Render the astro custom 404 page const response = await app.render(request); - if(app.setCookieHeaders) { - for(const setCookieHeader of app.setCookieHeaders(response)) { + if (app.setCookieHeaders) { + for (const setCookieHeader of app.setCookieHeaders(response)) { response.headers.append('Set-Cookie', setCookieHeader); } } diff --git a/packages/integrations/image/src/loaders/squoosh.ts b/packages/integrations/image/src/loaders/squoosh.ts index 95dda9e47..455d476d8 100644 --- a/packages/integrations/image/src/loaders/squoosh.ts +++ b/packages/integrations/image/src/loaders/squoosh.ts @@ -111,12 +111,7 @@ class SquooshService extends BaseSSRService { throw new Error(`Unknown image output: "${transform.format}" used for ${transform.src}`); } - const data = await processBuffer( - inputBuffer, - operations, - transform.format, - transform.quality - ); + const data = await processBuffer(inputBuffer, operations, transform.format, transform.quality); return { data: Buffer.from(data), diff --git a/packages/integrations/netlify/src/netlify-edge-functions.ts b/packages/integrations/netlify/src/netlify-edge-functions.ts index c788b5f67..f4766b276 100644 --- a/packages/integrations/netlify/src/netlify-edge-functions.ts +++ b/packages/integrations/netlify/src/netlify-edge-functions.ts @@ -18,8 +18,8 @@ export function createExports(manifest: SSRManifest) { const ip = request.headers.get('x-nf-client-connection-ip'); Reflect.set(request, clientAddressSymbol, ip); const response = await app.render(request); - if(app.setCookieHeaders) { - for(const setCookieHeader of app.setCookieHeaders(response)) { + if (app.setCookieHeaders) { + for (const setCookieHeader of app.setCookieHeaders(response)) { response.headers.append('Set-Cookie', setCookieHeader); } } diff --git a/packages/integrations/netlify/src/netlify-functions.ts b/packages/integrations/netlify/src/netlify-functions.ts index 7945b4687..7ca551022 100644 --- a/packages/integrations/netlify/src/netlify-functions.ts +++ b/packages/integrations/netlify/src/netlify-functions.ts @@ -121,10 +121,10 @@ export const createExports = (manifest: SSRManifest, args: Args) => { } // Apply cookies set via Astro.cookies.set/delete - if(app.setCookieHeaders) { + if (app.setCookieHeaders) { const setCookieHeaders = Array.from(app.setCookieHeaders(response)); fnResponse.multiValueHeaders = fnResponse.multiValueHeaders || {}; - if(!fnResponse.multiValueHeaders['set-cookie']) { + if (!fnResponse.multiValueHeaders['set-cookie']) { fnResponse.multiValueHeaders['set-cookie'] = []; } fnResponse.multiValueHeaders['set-cookie'].push(...setCookieHeaders); diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index 794580ee9..6ecd14931 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -42,9 +42,9 @@ export function createExports(manifest: SSRManifest) { async function writeWebResponse(app: NodeApp, res: ServerResponse, webResponse: Response) { const { status, headers, body } = webResponse; - if(app.setCookieHeaders) { + if (app.setCookieHeaders) { const setCookieHeaders: Array = Array.from(app.setCookieHeaders(webResponse)); - if(setCookieHeaders.length) { + if (setCookieHeaders.length) { res.setHeader('Set-Cookie', setCookieHeaders); } } diff --git a/packages/integrations/vercel/src/edge/entrypoint.ts b/packages/integrations/vercel/src/edge/entrypoint.ts index b37421744..a9870ef2b 100644 --- a/packages/integrations/vercel/src/edge/entrypoint.ts +++ b/packages/integrations/vercel/src/edge/entrypoint.ts @@ -16,8 +16,8 @@ export function createExports(manifest: SSRManifest) { if (app.match(request)) { Reflect.set(request, clientAddressSymbol, request.headers.get('x-forwarded-for')); const response = await app.render(request); - if(app.setCookieHeaders) { - for(const setCookieHeader of app.setCookieHeaders(response)) { + if (app.setCookieHeaders) { + for (const setCookieHeader of app.setCookieHeaders(response)) { response.headers.append('Set-Cookie', setCookieHeader); } } diff --git a/packages/integrations/vercel/src/serverless/request-transform.ts b/packages/integrations/vercel/src/serverless/request-transform.ts index 97337751f..7212431c7 100644 --- a/packages/integrations/vercel/src/serverless/request-transform.ts +++ b/packages/integrations/vercel/src/serverless/request-transform.ts @@ -1,5 +1,5 @@ -import type { IncomingMessage, ServerResponse } from 'node:http'; import type { App } from 'astro/app'; +import type { IncomingMessage, ServerResponse } from 'node:http'; import { Readable } from 'node:stream'; const clientAddressSymbol = Symbol.for('astro.clientAddress'); @@ -78,7 +78,11 @@ export async function getRequest(base: string, req: IncomingMessage): Promise { +export async function setResponse( + app: App, + res: ServerResponse, + response: Response +): Promise { const headers = Object.fromEntries(response.headers); if (response.headers.has('set-cookie')) { @@ -86,9 +90,9 @@ export async function setResponse(app: App, res: ServerResponse, response: Respo headers['set-cookie'] = response.headers.raw()['set-cookie']; } - if(app.setCookieHeaders) { + if (app.setCookieHeaders) { const setCookieHeaders: Array = Array.from(app.setCookieHeaders(response)); - if(setCookieHeaders.length) { + if (setCookieHeaders.length) { res.setHeader('Set-Cookie', setCookieHeaders); } }