From 0f0625504145f18cba7dc6cf20291cb2abddc5a9 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 26 Jul 2023 08:53:31 +0100 Subject: [PATCH] feat: upper case the name of the endpoints (#7783) Co-authored-by: Bjorn Lu Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Chris Swithinbank --- .changeset/twelve-coats-rush.md | 35 +++++++++++++++++ packages/astro/src/assets/image-endpoint.ts | 2 +- packages/astro/src/core/endpoint/index.ts | 6 +-- packages/astro/src/runtime/server/endpoint.ts | 38 ++++++++++++++++--- .../api-routes/src/pages/binary.dat.ts | 2 +- .../src/pages/context/data/[param].json.js | 2 +- .../astro-cookies/src/pages/set-prefs.js | 2 +- .../src/pages/data/[slug].json.ts | 2 +- .../src/pages/glob.json.js | 2 +- .../src/pages/headings-glob.json.js | 2 +- .../src/pages/raw-content.json.js | 2 +- .../src/pages/vite-env-vars-glob.json.js | 2 +- .../src/pages/welcome-data.json.js | 2 +- .../src/pages/collections.json.js | 2 +- .../src/pages/entries.json.js | 2 +- .../fixtures/core-image-ssr/src/pages/api.ts | 2 +- .../src/pages/authors/[id].json.js | 2 +- .../src/pages/authors/all.json.js | 2 +- .../src/pages/translations/[lang].json.js | 2 +- .../src/pages/translations/all.json.js | 2 +- .../src/pages/api/catch/[...slug].ts | 2 +- .../middleware-dev/src/pages/api/endpoint.js | 2 +- .../non-html-pages/src/pages/about.json.ts | 2 +- .../src/pages/placeholder.png.ts | 2 +- .../src/pages/api/catch/[...slug].json.ts | 2 +- .../src/pages/api/catch/[foo]-[bar].json.ts | 2 +- .../src/pages/api/route.js | 2 +- .../ssr-api-route/src/pages/binary.js | 2 +- .../src/pages/context/[param].js | 2 +- .../ssr-api-route/src/pages/food.json.js | 4 +- .../fixtures/ssr-api-route/src/pages/login.js | 2 +- .../src/pages/api/products/[id].js | 2 +- .../test/fixtures/ssr-locals/src/pages/api.js | 2 +- .../src/pages/data/[slug].json.ts | 2 +- .../static-build/src/pages/company.json.ts | 4 +- .../src/pages/data/[slug].json.ts | 4 +- .../static-build/src/pages/posts.json.js | 2 +- .../src/pages/[slug].json.ts | 2 +- .../src/pages/data/[slug].json.ts | 2 +- .../src/pages/home.json.ts | 2 +- .../src/pages/images/[image].svg.ts | 2 +- .../src/pages/images/hex.ts | 2 +- .../src/pages/images/static.svg.ts | 2 +- packages/integrations/image/src/endpoint.ts | 2 +- .../html/transform/html-token-transform.ts | 2 +- 45 files changed, 116 insertions(+), 53 deletions(-) create mode 100644 .changeset/twelve-coats-rush.md diff --git a/.changeset/twelve-coats-rush.md b/.changeset/twelve-coats-rush.md new file mode 100644 index 000000000000..29dd0f689b63 --- /dev/null +++ b/.changeset/twelve-coats-rush.md @@ -0,0 +1,35 @@ +--- +'astro': major +--- + +Lowercase names for endpoint functions are now deprecated. + +Rename functions to their uppercase equivalent: + +```diff +- export function get() { ++ export function GET() { + return new Response(JSON.stringify({ "title": "Bob's blog" })); +} + +- export function post() { ++ export function POST() { + return new Response(JSON.stringify({ "title": "Bob's blog" })); +} + +- export function put() { ++ export function PUT() { + return new Response(JSON.stringify({ "title": "Bob's blog" })); +} + +- export function all() { ++ export function ALL() { + return new Response(JSON.stringify({ "title": "Bob's blog" })); +} + +// you can use the whole word "DELETE" +- export function del() { ++ export function DELETE() { + return new Response(JSON.stringify({ "title": "Bob's blog" })); +} +``` diff --git a/packages/astro/src/assets/image-endpoint.ts b/packages/astro/src/assets/image-endpoint.ts index 0553272c219c..8dc15c36ae5c 100644 --- a/packages/astro/src/assets/image-endpoint.ts +++ b/packages/astro/src/assets/image-endpoint.ts @@ -24,7 +24,7 @@ async function loadRemoteImage(src: URL) { /** * Endpoint used in dev and SSR to serve optimized images by the base image services */ -export const get: APIRoute = async ({ request }) => { +export const GET: APIRoute = async ({ request }) => { try { const imageService = await getConfiguredImageService(); diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index 392ffa291e55..b35895197dd0 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -7,13 +7,13 @@ import type { Params, } from '../../@types/astro'; import type { Environment, RenderContext } from '../render/index'; - import { renderEndpoint } from '../../runtime/server/index.js'; import { ASTRO_VERSION } from '../constants.js'; import { AstroCookies, attachToResponse } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import { warn } from '../logger/core.js'; import { callMiddleware } from '../middleware/callMiddleware.js'; + const clientAddressSymbol = Symbol.for('astro.clientAddress'); const clientLocalsSymbol = Symbol.for('astro.locals'); @@ -119,11 +119,11 @@ export async function callEndpoint onRequest as MiddlewareEndpointHandler, context, async () => { - return await renderEndpoint(mod, context, env.ssr); + return await renderEndpoint(mod, context, env.ssr, env.logging); } ); } else { - response = await renderEndpoint(mod, context, env.ssr); + response = await renderEndpoint(mod, context, env.ssr, env.logging); } if (response instanceof Response) { diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index c56ab764602c..560026313ae1 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -1,28 +1,56 @@ import type { APIContext, EndpointHandler, Params } from '../../@types/astro'; +import { type LogOptions, warn } from '../../core/logger/core.js'; -function getHandlerFromModule(mod: EndpointHandler, method: string) { +function getHandlerFromModule(mod: EndpointHandler, method: string, logging: LogOptions) { + const lowerCaseMethod = method.toLowerCase(); + + // TODO: remove in Astro 4.0 + if (mod[lowerCaseMethod]) { + warn( + logging, + 'astro', + `Lower case endpoint names are deprecated and will not be supported in Astro 4.0. Rename the endpoint ${lowerCaseMethod} to ${method}.` + ); + } // If there was an exact match on `method`, return that function. if (mod[method]) { return mod[method]; } + + // TODO: remove in Astro 4.0 + if (mod[lowerCaseMethod]) { + return mod[lowerCaseMethod]; + } + // TODO: remove in Astro 4.0 // Handle `del` instead of `delete`, since `delete` is a reserved word in JS. if (method === 'delete' && mod['del']) { return mod['del']; } + // TODO: remove in Astro 4.0 // If a single `all` handler was used, return that function. if (mod['all']) { return mod['all']; } + if (mod['ALL']) { + return mod['ALL']; + } // Otherwise, no handler found. return undefined; } /** Renders an endpoint request to completion, returning the body. */ -export async function renderEndpoint(mod: EndpointHandler, context: APIContext, ssr: boolean) { +export async function renderEndpoint( + mod: EndpointHandler, + context: APIContext, + ssr: boolean, + logging: LogOptions +) { const { request, params } = context; - const chosenMethod = request.method?.toLowerCase(); - const handler = getHandlerFromModule(mod, chosenMethod); - if (!ssr && ssr === false && chosenMethod && chosenMethod !== 'get') { + + const chosenMethod = request.method?.toUpperCase(); + const handler = getHandlerFromModule(mod, chosenMethod, logging); + // TODO: remove the 'get' check in Astro 4.0 + if (!ssr && ssr === false && chosenMethod && chosenMethod !== 'GET' && chosenMethod !== 'get') { // eslint-disable-next-line no-console console.warn(` ${chosenMethod} requests are not available when building a static site. Update your config to \`output: 'server'\` or \`output: 'hybrid'\` with an \`export const prerender = false\` to handle ${chosenMethod} requests.`); diff --git a/packages/astro/test/fixtures/api-routes/src/pages/binary.dat.ts b/packages/astro/test/fixtures/api-routes/src/pages/binary.dat.ts index c735896335de..cbd382fc327c 100644 --- a/packages/astro/test/fixtures/api-routes/src/pages/binary.dat.ts +++ b/packages/astro/test/fixtures/api-routes/src/pages/binary.dat.ts @@ -1,5 +1,5 @@ import type { APIRoute } from 'astro'; -export const get: APIRoute = async function () { +export const GET: APIRoute = async function () { return new Response(new Uint8Array([0xff])); }; diff --git a/packages/astro/test/fixtures/api-routes/src/pages/context/data/[param].json.js b/packages/astro/test/fixtures/api-routes/src/pages/context/data/[param].json.js index 2ed42a5ec5a9..d18eb086f9a5 100644 --- a/packages/astro/test/fixtures/api-routes/src/pages/context/data/[param].json.js +++ b/packages/astro/test/fixtures/api-routes/src/pages/context/data/[param].json.js @@ -14,7 +14,7 @@ export function getStaticPaths() { ] } -export function get({ params, request }) { +export function GET({ params, request }) { return { body: JSON.stringify({ param: params.param, diff --git a/packages/astro/test/fixtures/astro-cookies/src/pages/set-prefs.js b/packages/astro/test/fixtures/astro-cookies/src/pages/set-prefs.js index ccbdceff618f..93a6a96de999 100644 --- a/packages/astro/test/fixtures/astro-cookies/src/pages/set-prefs.js +++ b/packages/astro/test/fixtures/astro-cookies/src/pages/set-prefs.js @@ -1,5 +1,5 @@ -export function post({ cookies }) { +export function POST({ cookies }) { const mode = cookies.get('prefs').json().mode; cookies.set('prefs', { diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/data/[slug].json.ts b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/data/[slug].json.ts index 3c7cc63baa00..32a0fd140f12 100644 --- a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/data/[slug].json.ts +++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/data/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ]; } -export async function get() { +export async function GET() { return { body: JSON.stringify({ title: '[slug]' diff --git a/packages/astro/test/fixtures/astro-markdown-frontmatter-injection/src/pages/glob.json.js b/packages/astro/test/fixtures/astro-markdown-frontmatter-injection/src/pages/glob.json.js index a56f5306fd00..3aae6d89a8a9 100644 --- a/packages/astro/test/fixtures/astro-markdown-frontmatter-injection/src/pages/glob.json.js +++ b/packages/astro/test/fixtures/astro-markdown-frontmatter-injection/src/pages/glob.json.js @@ -1,4 +1,4 @@ -export async function get() { +export async function GET() { const docs = await import.meta.glob('./*.md', { eager: true }); return { body: JSON.stringify(Object.values(docs).map(doc => doc.frontmatter)), diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/headings-glob.json.js b/packages/astro/test/fixtures/astro-markdown/src/pages/headings-glob.json.js index 631250c33d5c..b2c9ea6ea25f 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/headings-glob.json.js +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/headings-glob.json.js @@ -1,6 +1,6 @@ import { getHeadings } from './with-layout.md'; -export async function get() { +export async function GET() { return { body: JSON.stringify({ headings: getHeadings(), diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/raw-content.json.js b/packages/astro/test/fixtures/astro-markdown/src/pages/raw-content.json.js index ef933a373ae8..82977443dc11 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/raw-content.json.js +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/raw-content.json.js @@ -1,6 +1,6 @@ import { rawContent, compiledContent } from './basic.md'; -export async function get() { +export async function GET() { return { body: JSON.stringify({ raw: rawContent(), diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/vite-env-vars-glob.json.js b/packages/astro/test/fixtures/astro-markdown/src/pages/vite-env-vars-glob.json.js index 4a7e4dd783db..7a5d00f47ac0 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/vite-env-vars-glob.json.js +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/vite-env-vars-glob.json.js @@ -1,6 +1,6 @@ import { frontmatter } from './vite-env-vars.md'; -export async function get() { +export async function GET() { return { body: JSON.stringify(frontmatter), } diff --git a/packages/astro/test/fixtures/content-collection-references/src/pages/welcome-data.json.js b/packages/astro/test/fixtures/content-collection-references/src/pages/welcome-data.json.js index 4f529dac61b0..a461a1a65f89 100644 --- a/packages/astro/test/fixtures/content-collection-references/src/pages/welcome-data.json.js +++ b/packages/astro/test/fixtures/content-collection-references/src/pages/welcome-data.json.js @@ -1,6 +1,6 @@ import { getEntry, getEntries } from 'astro:content'; -export async function get() { +export async function GET() { const welcomePost = await getEntry('blog', 'welcome'); if (!welcomePost?.data) { diff --git a/packages/astro/test/fixtures/content-collections/src/pages/collections.json.js b/packages/astro/test/fixtures/content-collections/src/pages/collections.json.js index e74d03ad9bd5..e335d2b05d7c 100644 --- a/packages/astro/test/fixtures/content-collections/src/pages/collections.json.js +++ b/packages/astro/test/fixtures/content-collections/src/pages/collections.json.js @@ -2,7 +2,7 @@ import { getCollection } from 'astro:content'; import * as devalue from 'devalue'; import { stripAllRenderFn } from '../utils.js'; -export async function get() { +export async function GET() { const withoutConfig = stripAllRenderFn(await getCollection('without-config')); const withSchemaConfig = stripAllRenderFn(await getCollection('with-schema-config')); const withSlugConfig = stripAllRenderFn(await getCollection('with-custom-slugs')); diff --git a/packages/astro/test/fixtures/content-collections/src/pages/entries.json.js b/packages/astro/test/fixtures/content-collections/src/pages/entries.json.js index 0d7d22d0861f..311b76cc8bca 100644 --- a/packages/astro/test/fixtures/content-collections/src/pages/entries.json.js +++ b/packages/astro/test/fixtures/content-collections/src/pages/entries.json.js @@ -2,7 +2,7 @@ import { getEntryBySlug } from 'astro:content'; import * as devalue from 'devalue'; import { stripRenderFn } from '../utils.js'; -export async function get() { +export async function GET() { const columbiaWithoutConfig = stripRenderFn(await getEntryBySlug('without-config', 'columbia')); const oneWithSchemaConfig = stripRenderFn(await getEntryBySlug('with-schema-config', 'one')); const twoWithSlugConfig = stripRenderFn(await getEntryBySlug('with-custom-slugs', 'interesting-two')); diff --git a/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts b/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts index c10946318d82..7847baf62cb8 100644 --- a/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts +++ b/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts @@ -1,6 +1,6 @@ import type { APIRoute } from "../../../../../src/@types/astro"; -export const get = (async ({ params, request }) => { +export const GET = (async ({ params, request }) => { const url = new URL(request.url); const src = url.searchParams.get("src"); diff --git a/packages/astro/test/fixtures/data-collections/src/pages/authors/[id].json.js b/packages/astro/test/fixtures/data-collections/src/pages/authors/[id].json.js index 1cc26fb73694..76f4d57606d2 100644 --- a/packages/astro/test/fixtures/data-collections/src/pages/authors/[id].json.js +++ b/packages/astro/test/fixtures/data-collections/src/pages/authors/[id].json.js @@ -7,7 +7,7 @@ export function getStaticPaths() { } /** @param {import('astro').APIContext} params */ -export async function get({ params }) { +export async function GET({ params }) { const { id } = params; const author = await getEntry('authors-without-config', id); if (!author) { diff --git a/packages/astro/test/fixtures/data-collections/src/pages/authors/all.json.js b/packages/astro/test/fixtures/data-collections/src/pages/authors/all.json.js index e4c80406456a..5b5007fedb70 100644 --- a/packages/astro/test/fixtures/data-collections/src/pages/authors/all.json.js +++ b/packages/astro/test/fixtures/data-collections/src/pages/authors/all.json.js @@ -1,6 +1,6 @@ import { getCollection } from 'astro:content'; -export async function get() { +export async function GET() { const authors = await getCollection('authors-without-config'); return { diff --git a/packages/astro/test/fixtures/data-collections/src/pages/translations/[lang].json.js b/packages/astro/test/fixtures/data-collections/src/pages/translations/[lang].json.js index 73c90354d3c5..ab8cc764e353 100644 --- a/packages/astro/test/fixtures/data-collections/src/pages/translations/[lang].json.js +++ b/packages/astro/test/fixtures/data-collections/src/pages/translations/[lang].json.js @@ -7,7 +7,7 @@ export function getStaticPaths() { } /** @param {import('astro').APIContext} params */ -export async function get({ params }) { +export async function GET({ params }) { const { lang } = params; const translations = await getEntry('i18n', lang); if (!translations) { diff --git a/packages/astro/test/fixtures/data-collections/src/pages/translations/all.json.js b/packages/astro/test/fixtures/data-collections/src/pages/translations/all.json.js index 7d953838f3f2..e8a1fee92908 100644 --- a/packages/astro/test/fixtures/data-collections/src/pages/translations/all.json.js +++ b/packages/astro/test/fixtures/data-collections/src/pages/translations/all.json.js @@ -1,6 +1,6 @@ import { getCollection } from 'astro:content'; -export async function get() { +export async function GET() { const translations = await getCollection('i18n'); return { diff --git a/packages/astro/test/fixtures/dynamic-endpoint-collision/src/pages/api/catch/[...slug].ts b/packages/astro/test/fixtures/dynamic-endpoint-collision/src/pages/api/catch/[...slug].ts index 8f64c2401ffa..8fccd6695a8c 100644 --- a/packages/astro/test/fixtures/dynamic-endpoint-collision/src/pages/api/catch/[...slug].ts +++ b/packages/astro/test/fixtures/dynamic-endpoint-collision/src/pages/api/catch/[...slug].ts @@ -2,7 +2,7 @@ import type { APIRoute } from "astro"; const slugs = ["one", undefined]; -export const get: APIRoute = ({ params }) => { +export const GET: APIRoute = ({ params }) => { return { body: JSON.stringify({ slug: params.slug || "index", diff --git a/packages/astro/test/fixtures/middleware-dev/src/pages/api/endpoint.js b/packages/astro/test/fixtures/middleware-dev/src/pages/api/endpoint.js index dadff6edb77d..69d989bc0786 100644 --- a/packages/astro/test/fixtures/middleware-dev/src/pages/api/endpoint.js +++ b/packages/astro/test/fixtures/middleware-dev/src/pages/api/endpoint.js @@ -1,4 +1,4 @@ -export function get() { +export function GET() { const object = { name: 'Endpoint!!', }; diff --git a/packages/astro/test/fixtures/non-html-pages/src/pages/about.json.ts b/packages/astro/test/fixtures/non-html-pages/src/pages/about.json.ts index af61847f3a32..0c3ec18ea449 100644 --- a/packages/astro/test/fixtures/non-html-pages/src/pages/about.json.ts +++ b/packages/astro/test/fixtures/non-html-pages/src/pages/about.json.ts @@ -1,7 +1,7 @@ // 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() { +export async function GET() { return { body: JSON.stringify({ name: 'Astro', diff --git a/packages/astro/test/fixtures/non-html-pages/src/pages/placeholder.png.ts b/packages/astro/test/fixtures/non-html-pages/src/pages/placeholder.png.ts index 0c2d3806b2a1..3ee26f0bfc2d 100644 --- a/packages/astro/test/fixtures/non-html-pages/src/pages/placeholder.png.ts +++ b/packages/astro/test/fixtures/non-html-pages/src/pages/placeholder.png.ts @@ -2,7 +2,7 @@ import { promises as fs } from 'node:fs'; import type { APIRoute } from 'astro'; -export const get: APIRoute = async function get() { +export const GET: APIRoute = async function get() { try { // Image is in the public domain. Sourced from // https://en.wikipedia.org/wiki/File:Portrait_placeholder.png diff --git a/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[...slug].json.ts b/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[...slug].json.ts index 142b11711c0b..bc7e1b774698 100644 --- a/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[...slug].json.ts +++ b/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[...slug].json.ts @@ -1,6 +1,6 @@ import type { APIRoute } from 'astro'; -export const get: APIRoute = async ({ params }) => { +export const GET: APIRoute = async ({ params }) => { return { body: JSON.stringify({ path: params.slug, diff --git a/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[foo]-[bar].json.ts b/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[foo]-[bar].json.ts index 2e66a22ae51a..b06efff6f213 100644 --- a/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[foo]-[bar].json.ts +++ b/packages/astro/test/fixtures/routing-priority/src/pages/api/catch/[foo]-[bar].json.ts @@ -1,6 +1,6 @@ import type { APIRoute } from 'astro'; -export const get: APIRoute = async ({ params }) => { +export const GET: APIRoute = async ({ params }) => { return { body: JSON.stringify({ foo: params.foo, diff --git a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/api/route.js b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/api/route.js index c44461be9826..5a1cacc115bc 100644 --- a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/api/route.js +++ b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/api/route.js @@ -1,5 +1,5 @@ -export function post() { +export function POST() { return { body: JSON.stringify({ ok: true }) }; diff --git a/packages/astro/test/fixtures/ssr-api-route/src/pages/binary.js b/packages/astro/test/fixtures/ssr-api-route/src/pages/binary.js index 3e1c70c81502..407c45666af0 100644 --- a/packages/astro/test/fixtures/ssr-api-route/src/pages/binary.js +++ b/packages/astro/test/fixtures/ssr-api-route/src/pages/binary.js @@ -1,6 +1,6 @@ import fs from 'node:fs'; -export function get() { +export function GET() { return { body: 'ok' }; diff --git a/packages/astro/test/fixtures/ssr-api-route/src/pages/context/[param].js b/packages/astro/test/fixtures/ssr-api-route/src/pages/context/[param].js index 0ff1f625aaf8..ba110ee13f4d 100644 --- a/packages/astro/test/fixtures/ssr-api-route/src/pages/context/[param].js +++ b/packages/astro/test/fixtures/ssr-api-route/src/pages/context/[param].js @@ -1,7 +1,7 @@ /** * @param {import('astro').APIContext} api */ -export function get(ctx) { +export function GET(ctx) { return { body: JSON.stringify({ cookiesExist: !!ctx.cookies, diff --git a/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js b/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js index 1f9ea5f295b5..f4021c9e5442 100644 --- a/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js +++ b/packages/astro/test/fixtures/ssr-api-route/src/pages/food.json.js @@ -1,5 +1,5 @@ -export function get() { +export function GET() { return { body: JSON.stringify([ { name: 'lettuce' }, @@ -9,7 +9,7 @@ export function get() { }; } -export async function post({ params, request }) { +export async function POST({ params, request }) { const body = await request.text(); return new Response(body === `some data` ? `ok` : `not ok`, { status: 200, diff --git a/packages/astro/test/fixtures/ssr-api-route/src/pages/login.js b/packages/astro/test/fixtures/ssr-api-route/src/pages/login.js index dfce0b5d69fd..0e851df749bc 100644 --- a/packages/astro/test/fixtures/ssr-api-route/src/pages/login.js +++ b/packages/astro/test/fixtures/ssr-api-route/src/pages/login.js @@ -1,5 +1,5 @@ /** @type {import('astro').APIRoute} */ -export function post({ cookies }) { +export function POST({ cookies }) { cookies.set('foo', 'foo', { httpOnly: true }); diff --git a/packages/astro/test/fixtures/ssr-dynamic/src/pages/api/products/[id].js b/packages/astro/test/fixtures/ssr-dynamic/src/pages/api/products/[id].js index 4d96b62a5e4f..8c7c393029c1 100644 --- a/packages/astro/test/fixtures/ssr-dynamic/src/pages/api/products/[id].js +++ b/packages/astro/test/fixtures/ssr-dynamic/src/pages/api/products/[id].js @@ -1,5 +1,5 @@ -export function get({ params }) { +export function GET({ params }) { return { body: JSON.stringify(params) }; diff --git a/packages/astro/test/fixtures/ssr-locals/src/pages/api.js b/packages/astro/test/fixtures/ssr-locals/src/pages/api.js index d4f7386fb85c..366f26aaeec1 100644 --- a/packages/astro/test/fixtures/ssr-locals/src/pages/api.js +++ b/packages/astro/test/fixtures/ssr-locals/src/pages/api.js @@ -1,5 +1,5 @@ -export async function get({ locals }) { +export async function GET({ locals }) { let out = { ...locals }; return new Response(JSON.stringify(out), { diff --git a/packages/astro/test/fixtures/ssr-prerender-get-static-paths/src/pages/data/[slug].json.ts b/packages/astro/test/fixtures/ssr-prerender-get-static-paths/src/pages/data/[slug].json.ts index 16e2a90cad53..d969873c54d1 100644 --- a/packages/astro/test/fixtures/ssr-prerender-get-static-paths/src/pages/data/[slug].json.ts +++ b/packages/astro/test/fixtures/ssr-prerender-get-static-paths/src/pages/data/[slug].json.ts @@ -7,7 +7,7 @@ export async function getStaticPaths() { ]; } -export async function get() { +export async function GET() { return { body: JSON.stringify({ title: '[slug]' diff --git a/packages/astro/test/fixtures/static-build/src/pages/company.json.ts b/packages/astro/test/fixtures/static-build/src/pages/company.json.ts index ee3f2f1add77..08f45a7b87f8 100644 --- a/packages/astro/test/fixtures/static-build/src/pages/company.json.ts +++ b/packages/astro/test/fixtures/static-build/src/pages/company.json.ts @@ -1,8 +1,8 @@ -export async function get() { +export async function GET() { return { body: JSON.stringify({ name: 'Astro Technology Company', url: 'https://astro.build/' }) } -} \ No newline at end of file +} diff --git a/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts b/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts index 2bcfe50a13fa..2fa13ac1820e 100644 --- a/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts +++ b/packages/astro/test/fixtures/static-build/src/pages/data/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ] } -export async function get({ params }) { +export async function GET({ params }) { return { body: JSON.stringify({ slug: params.slug, @@ -13,4 +13,4 @@ export async function get({ params }) { url: 'https://astro.build/' }) } -} \ No newline at end of file +} diff --git a/packages/astro/test/fixtures/static-build/src/pages/posts.json.js b/packages/astro/test/fixtures/static-build/src/pages/posts.json.js index 6463fdbad2b9..aefbbffff72c 100644 --- a/packages/astro/test/fixtures/static-build/src/pages/posts.json.js +++ b/packages/astro/test/fixtures/static-build/src/pages/posts.json.js @@ -13,7 +13,7 @@ async function fetchPosts() { return posts.sort((a, b) => a.title.localeCompare(b.title)); } -export async function get() { +export async function GET() { const posts = await fetchPosts(); return { diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts index 364c886e30ed..783031605467 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ]; } -export async function get({ params }) { +export async function GET({ params }) { return { body: JSON.stringify({ slug: params.slug, diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts index 4392c7ee71e3..707c39fa9c9c 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/data/[slug].json.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ]; } -export async function get({ params }) { +export async function GET({ params }) { return { body: JSON.stringify({ slug: params.slug, diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/home.json.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/home.json.ts index 8046af6dfc27..5eaac42f1d57 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/home.json.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/home.json.ts @@ -1,4 +1,4 @@ -export async function get() { +export async function GET() { return { body: JSON.stringify({ title: 'home' diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/[image].svg.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/[image].svg.ts index e728394f4c95..c6fa88711671 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/[image].svg.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/[image].svg.ts @@ -5,7 +5,7 @@ export async function getStaticPaths() { ]; } -export async function get({ params }) { +export async function GET({ params }) { return { body: ` ${params.image} diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/hex.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/hex.ts index 546796fed331..84dd6dcaa19a 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/hex.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/hex.ts @@ -1,6 +1,6 @@ import { readFileSync } from "node:fs"; -export async function get({ params, request }) { +export async function GET({ params, request }) { const buffer = readFileSync(new URL('../../astro.png', import.meta.url)); return { body: buffer.toString('hex'), diff --git a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/static.svg.ts b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/static.svg.ts index 727a0eae8fb2..93fcf40228bc 100644 --- a/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/static.svg.ts +++ b/packages/astro/test/fixtures/with-endpoint-routes/src/pages/images/static.svg.ts @@ -1,4 +1,4 @@ -export async function get() { +export async function GET() { return { body: ` Static SVG diff --git a/packages/integrations/image/src/endpoint.ts b/packages/integrations/image/src/endpoint.ts index 5a8ca554ba40..d3810e5dd787 100644 --- a/packages/integrations/image/src/endpoint.ts +++ b/packages/integrations/image/src/endpoint.ts @@ -20,7 +20,7 @@ async function loadRemoteImage(src: URL) { } } -export const get: APIRoute = async ({ request }) => { +export const GET: APIRoute = async ({ request }) => { try { const url = new URL(request.url); const transform = loader.parseTransform(url.searchParams); diff --git a/packages/integrations/markdoc/src/html/transform/html-token-transform.ts b/packages/integrations/markdoc/src/html/transform/html-token-transform.ts index 0d5dcfb818b1..cfa511a9f90f 100644 --- a/packages/integrations/markdoc/src/html/transform/html-token-transform.ts +++ b/packages/integrations/markdoc/src/html/transform/html-token-transform.ts @@ -1,4 +1,4 @@ -import { Tokenizer } from '@markdoc/markdoc'; +import type { Tokenizer } from '@markdoc/markdoc'; import { Parser } from 'htmlparser2'; import type * as Token from 'markdown-it/lib/token';