summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/src/integration-functions.ts
blob: 4242a7b001846b606d4c609765a4a8e57be91e9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro';
import { createRedirects } from './shared.js';
import type { Args } from './netlify-functions.js';

export function getAdapter(args: Args = {}): AstroAdapter {
	return {
		name: '@astrojs/netlify/functions',
		serverEntrypoint: '@astrojs/netlify/netlify-functions.js',
		exports: ['handler'],
		args,
	};
}

interface NetlifyFunctionsOptions {
	dist?: URL;
	binaryMediaTypes?: string[];
}

function netlifyFunctions({ dist, binaryMediaTypes }: NetlifyFunctionsOptions = {}): AstroIntegration {
	let _config: AstroConfig;
	let entryFile: string;
	return {
		name: '@astrojs/netlify',
		hooks: {
			'astro:config:setup': ({ config }) => {
				if (dist) {
					config.outDir = dist;
				} else {
					config.outDir = new URL('./dist/', config.root);
				}
			},
			'astro:config:done': ({ config, setAdapter }) => {
				setAdapter(getAdapter({ binaryMediaTypes }));
				_config = config;
			},
			'astro:build:start': async ({ buildConfig }) => {
				entryFile = buildConfig.serverEntry.replace(/\.m?js/, '');
				buildConfig.client = _config.outDir;
				buildConfig.server = new URL('./.netlify/functions-internal/', _config.root);
			},
			'astro:build:done': async ({ routes, dir }) => {
				await createRedirects(routes, dir, entryFile, false);
			},
		},
	};
}

export { netlifyFunctions, netlifyFunctions as default };
ertions'>+1 2022-02-03[ci] yarn formatGravatar FredKSchott 2-3/+85 2022-02-02Handles all http error code file names the same as 404 files. (#2525)Gravatar Zade Viggers 2-4/+7 2022-02-02fix(sitemap): remove debug if sitemap disabled (#2514)Gravatar Mark Pinero 1-2/+2 2022-02-02[ci] update lockfile (#2515)Gravatar Fred K. Schott 1-276/+279 2022-02-02[ci] yarn formatGravatar matthewp 1-8/+8 2022-02-02[ci] release (next) (#2523)astro@0.23.0-next.1Gravatar github-actions[bot] 28-34/+41 2022-02-02[ci] yarn formatGravatar matthewp 2-17/+29 2022-02-02Fix support for scss in static build (#2522)Gravatar Matthew Phillips 6-20/+114 2022-02-02[ci] collect statsGravatar FredKSchott 1-0/+1 2022-02-01[ci] yarn formatGravatar matthewp 2-12/+12 2022-02-01[ci] release (next) (#2492)astro@0.23.0-next.0@astrojs/test-static-build-pkg@0.0.2@astrojs/markdown-remark@0.6.1-next.0Gravatar github-actions[bot] 31-43/+93 2022-02-01[ci] collect statsGravatar FredKSchott 1-0/+1 2022-01-31update congratsbot format againGravatar Fred K. Schott 1-1/+1 2022-01-31update congratsbot againGravatar Fred K. Schott 1-1/+1 2022-01-31Remove SVG animation on GitHub/NPM (#2512)Gravatar Nate Moore 1-21/+0 2022-01-31[ci] yarn formatGravatar natemoo-re 2-4/+6 2022-01-31Add Shiki as an alternative to Prism (#2497)Gravatar Juan Martín Seery 26-9/+356 2022-01-31Deprecate unescaped HTML inside of expressions (#2489)Gravatar Nate Moore 9-31/+74