From d92ab065445b2ba904f01dae2c320d70af1e1f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=91=9E=E4=B8=B0?= Date: Mon, 4 Sep 2023 23:10:39 +0800 Subject: [PATCH 1/4] Update examples & uppercase endpoints & fix response (#8391) Co-authored-by: liruifeng --- examples/blog/src/pages/rss.xml.js | 2 +- examples/non-html-pages/src/pages/about.json.ts | 12 +++++------- examples/ssr/src/pages/api/cart.ts | 16 ++++++---------- examples/ssr/src/pages/api/products.ts | 6 ++---- examples/ssr/src/pages/api/products/[id].ts | 6 ++---- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/examples/blog/src/pages/rss.xml.js b/examples/blog/src/pages/rss.xml.js index 7d054b92a..9ff9801e0 100644 --- a/examples/blog/src/pages/rss.xml.js +++ b/examples/blog/src/pages/rss.xml.js @@ -2,7 +2,7 @@ import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; import { SITE_TITLE, SITE_DESCRIPTION } from '../consts'; -export async function get(context) { +export async function GET(context) { const posts = await getCollection('blog'); return rss({ title: SITE_TITLE, diff --git a/examples/non-html-pages/src/pages/about.json.ts b/examples/non-html-pages/src/pages/about.json.ts index af61847f3..7f98ba9fe 100644 --- a/examples/non-html-pages/src/pages/about.json.ts +++ b/examples/non-html-pages/src/pages/about.json.ts @@ -1,11 +1,9 @@ // Returns the file body for this non-HTML file. // The content type is based off of the extension in the filename, // in this case: about.json. -export async function get() { - return { - body: JSON.stringify({ - name: 'Astro', - url: 'https://astro.build/', - }), - }; +export async function GET() { + return new Response(JSON.stringify({ + name: 'Astro', + url: 'https://astro.build/', + })); } diff --git a/examples/ssr/src/pages/api/cart.ts b/examples/ssr/src/pages/api/cart.ts index 80db01f16..12c1b857a 100644 --- a/examples/ssr/src/pages/api/cart.ts +++ b/examples/ssr/src/pages/api/cart.ts @@ -1,7 +1,7 @@ import { APIContext } from 'astro'; import { userCartItems } from '../../models/session'; -export function get({ cookies }: APIContext) { +export function GET({ cookies }: APIContext) { let userId = cookies.get('user-id').value; if (!userId || !userCartItems.has(userId)) { @@ -12,9 +12,7 @@ export function get({ cookies }: APIContext) { let items = userCartItems.get(userId); let array = Array.from(items.values()); - return { - body: JSON.stringify({ items: array }), - }; + return new Response(JSON.stringify({ items: array })); } interface AddToCartItem { @@ -22,7 +20,7 @@ interface AddToCartItem { name: string; } -export async function post({ cookies, request }: APIContext) { +export async function POST({ cookies, request }: APIContext) { const item: AddToCartItem = await request.json(); let userId = cookies.get('user-id').value; @@ -38,9 +36,7 @@ export async function post({ cookies, request }: APIContext) { cart.set(item.id, { id: item.id, name: item.name, count: 1 }); } - return { - body: JSON.stringify({ - ok: true, - }), - }; + return new Response(JSON.stringify({ + ok: true, + })); } diff --git a/examples/ssr/src/pages/api/products.ts b/examples/ssr/src/pages/api/products.ts index 171291004..8bf02a03d 100644 --- a/examples/ssr/src/pages/api/products.ts +++ b/examples/ssr/src/pages/api/products.ts @@ -1,7 +1,5 @@ import { products } from '../../models/db'; -export function get() { - return { - body: JSON.stringify(products), - }; +export function GET() { + return new Response(JSON.stringify(products)); } diff --git a/examples/ssr/src/pages/api/products/[id].ts b/examples/ssr/src/pages/api/products/[id].ts index 7b8a98d64..abcd02da8 100644 --- a/examples/ssr/src/pages/api/products/[id].ts +++ b/examples/ssr/src/pages/api/products/[id].ts @@ -1,14 +1,12 @@ import { productMap } from '../../../models/db'; import type { APIContext } from 'astro'; -export function get({ params }: APIContext) { +export function GET({ params }: APIContext) { const id = Number(params.id); if (productMap.has(id)) { const product = productMap.get(id); - return { - body: JSON.stringify(product), - }; + return new Response(JSON.stringify(products)); } else { return new Response(null, { status: 400, From c48d4765c12ca28f4e1fa056959dce9016277b05 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 4 Sep 2023 15:12:28 +0000 Subject: [PATCH 2/4] [ci] format --- examples/non-html-pages/src/pages/about.json.ts | 10 ++++++---- examples/ssr/src/pages/api/cart.ts | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/non-html-pages/src/pages/about.json.ts b/examples/non-html-pages/src/pages/about.json.ts index 7f98ba9fe..8fa365724 100644 --- a/examples/non-html-pages/src/pages/about.json.ts +++ b/examples/non-html-pages/src/pages/about.json.ts @@ -2,8 +2,10 @@ // The content type is based off of the extension in the filename, // in this case: about.json. export async function GET() { - return new Response(JSON.stringify({ - name: 'Astro', - url: 'https://astro.build/', - })); + return new Response( + JSON.stringify({ + name: 'Astro', + url: 'https://astro.build/', + }) + ); } diff --git a/examples/ssr/src/pages/api/cart.ts b/examples/ssr/src/pages/api/cart.ts index 12c1b857a..cc6ba231b 100644 --- a/examples/ssr/src/pages/api/cart.ts +++ b/examples/ssr/src/pages/api/cart.ts @@ -36,7 +36,9 @@ export async function POST({ cookies, request }: APIContext) { cart.set(item.id, { id: item.id, name: item.name, count: 1 }); } - return new Response(JSON.stringify({ - ok: true, - })); + return new Response( + JSON.stringify({ + ok: true, + }) + ); } From b6066e109c5807f16dd81e07c81f300459e12897 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Tue, 5 Sep 2023 00:56:16 +0900 Subject: [PATCH 3/4] refactor: fix typo in astro.ts (#8385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elian ☕️ --- packages/astro/src/@types/astro.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index e8801d083..c6d27ab36 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1779,11 +1779,11 @@ export type AstroFeatureMap = { export interface AstroAssetsFeature { supportKind?: SupportsKind; /** - * Whether if this adapter deploys files in an enviroment that is compatible with the library `sharp` + * Whether if this adapter deploys files in an environment that is compatible with the library `sharp` */ isSharpCompatible?: boolean; /** - * Whether if this adapter deploys files in an enviroment that is compatible with the library `squoosh` + * Whether if this adapter deploys files in an environment that is compatible with the library `squoosh` */ isSquooshCompatible?: boolean; } From fd6ce9a99acb611cb0ec31b7875ae5ba02e23d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20D=C3=A9ramond?= Date: Tue, 5 Sep 2023 08:28:23 +0200 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20`funcitonPerRoute`=20=E2=86=92=20`fu?= =?UTF-8?q?nctionPerRoute`=20in=20vercel=20integ=20package=20(#8406)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/integrations/vercel/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/vercel/CHANGELOG.md b/packages/integrations/vercel/CHANGELOG.md index f936b71e1..c6a1cf30b 100644 --- a/packages/integrations/vercel/CHANGELOG.md +++ b/packages/integrations/vercel/CHANGELOG.md @@ -6,7 +6,7 @@ - [#8348](https://github.com/withastro/astro/pull/8348) [`5f2c55bb5`](https://github.com/withastro/astro/commit/5f2c55bb54bb66693d278b7cd705c198aecc0331) Thanks [@ematipico](https://github.com/ematipico)! - - Cache result during bundling, to speed up the process of multiple functions; - - Avoid creating multiple symbolic links of the dependencies when building the project with `funcitonPerRoute` enabled; + - Avoid creating multiple symbolic links of the dependencies when building the project with `functionPerRoute` enabled; - [#8354](https://github.com/withastro/astro/pull/8354) [`0eb09dbab`](https://github.com/withastro/astro/commit/0eb09dbab1674a57d23ac97950a527d2e5a9c9fb) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Fix unnecessary warning about Sharp showing while building