import type { AstroAdapter, AstroConfig, AstroIntegration, RouteData } from 'astro'; import { extname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { generateEdgeMiddleware } from './middleware.js'; import type { Args } from './netlify-functions.js'; import { createRedirects } from './shared.js'; export const NETLIFY_EDGE_MIDDLEWARE_FILE = 'netlify-edge-middleware'; export const ASTRO_LOCALS_HEADER = 'x-astro-locals'; export function getAdapter(args: Args = {}): AstroAdapter { return { name: '@astrojs/netlify/functions', serverEntrypoint: '@astrojs/netlify/netlify-functions.js', exports: ['handler'], args, }; } interface NetlifyFunctionsOptions { dist?: URL; builders?: boolean; binaryMediaTypes?: string[]; } function netlifyFunctions({ dist, builders, binaryMediaTypes, }: NetlifyFunctionsOptions = {}): AstroIntegration { let _config: AstroConfig; let _entryPoints: Map; let ssrEntryFile: string; let _middlewareEntryPoint: URL; return { name: '@astrojs/netlify', hooks: { 'astro:config:setup': ({ config, updateConfig }) => { const outDir = dist ?? new URL('./dist/', config.root); updateConfig({ outDir, build: { redirects: false, client: outDir, server: new URL('./.netlify/functions-internal/', config.root), }, }); }, 'astro:build:ssr': async ({ entryPoints, middlewareEntryPoint }) => { if (middlewareEntryPoint) { _middlewareEntryPoint = middlewareEntryPoint; } _entryPoints = entryPoints; }, 'astro:config:done': ({ config, setAdapter }) => { setAdapter(getAdapter({ binaryMediaTypes, builders })); _config = config; ssrEntryFile = config.build.serverEntry.replace(/\.m?js/, ''); if (config.output === 'static') { console.warn( `[@astrojs/netlify] \`output: "server"\` or \`output: "hybrid"\` is required to use this adapter.` ); console.warn( `[@astrojs/netlify] Otherwise, this adapter is not required to deploy a static site to Netlify.` ); } }, 'astro:build:done': async ({ routes, dir }) => { const type = builders ? 'builders' : 'functions'; const kind = type ?? 'functions'; if (_entryPoints.size) { const routeToDynamicTargetMap = new Map(); for (const [route, entryFile] of _entryPoints) { const wholeFileUrl = fileURLToPath(entryFile); const extension = extname(wholeFileUrl); const relative = wholeFileUrl .replace(fileURLToPath(_config.build.server), '') .replace(extension, '') .replaceAll('\\', '/'); const dynamicTarget = `/.netlify/${kind}/${relative}`; routeToDynamicTargetMap.set(route, dynamicTarget); } await createRedirects(_config, routeToDynamicTargetMap, dir); } else { const dynamicTarget = `/.netlify/${kind}/${ssrEntryFile}`; const map: [RouteData, string][] = routes.map((route) => { return [route, dynamicTarget]; }); const routeToDynamicTargetMap = new Map(Array.from(map)); await createRedirects(_config, routeToDynamicTargetMap, dir); } if (_middlewareEntryPoint) { const outPath = fileURLToPath(new URL('./.netlify/edge-functions/', _config.root)); const netlifyEdgeMiddlewareHandlerPath = new URL( NETLIFY_EDGE_MIDDLEWARE_FILE, _config.srcDir ); await generateEdgeMiddleware( _middlewareEntryPoint, outPath, netlifyEdgeMiddlewareHandlerPath ); } }, }, }; } export { netlifyFunctions as default, netlifyFunctions }; 'examples/component'>examples/component Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/packages/webapi/test/options.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-04-11[ci] formatGravatar FredKSchott 2-0/+2
2022-04-10fix up changelogsGravatar Fred K. Schott 13-56/+19
2022-04-10[ci] release (#3061)astro@1.0.0-beta.6@astrojs/vue@0.1.0@astrojs/vercel@0.1.0@astrojs/turbolinks@0.1.0@astrojs/tailwind@0.1.1@astrojs/svelte@0.1.0@astrojs/solid-js@0.1.0@astrojs/renderer-solid@0.4.1@astrojs/preact@0.1.0@astrojs/partytown@0.1.1@astrojs/node@0.1.0@astrojs/netlify@0.2.0@astrojs/lit@0.1.0Gravatar github-actions[bot] 76-329/+254
2022-04-10attempt to fix the 'no commits' bug in changesetGravatar Fred K. Schott 1-1/+1
2022-04-10revert releaseGravatar Fred K. Schott 76-225/+329
2022-04-10Update astro changelogGravatar Fred K. Schott 1-29/+0
2022-04-11[ci] formatGravatar FredKSchott 3-34/+34
2022-04-10[ci] release (#3060)Gravatar github-actions[bot] 76-363/+288
2022-04-10update changesetGravatar Fred K. Schott 1-1/+0
2022-04-10update changesetGravatar Fred K. Schott 1-1/+1
2022-04-10update lockfile (#3059)Gravatar Fred K. Schott 29-914/+698
2022-04-10correct changesetsGravatar Fred K. Schott 3-3/+11
2022-04-10chore: webapi test now use chai (#3048)Gravatar Juan Martín Seery 16-814/+539
2022-04-10update test names containing spacesGravatar Fred K. Schott 26-17/+17
2022-04-11[ci] formatGravatar FredKSchott 2-8/+7
2022-04-10Fix SSR static build public file copying. fixes #3016 (#3037)Gravatar Steve Lee 8-5/+48
2022-04-10fix our weird beta release issues (#3031)Gravatar Fred K. Schott 4-6/+116
2022-04-10update tailwind integration readmeGravatar Fred K. Schott 2-9/+38
2022-04-10Fixed MD Lint issues (#3038)Gravatar Rafid Muhymin Wafi 1-12/+11