From 77aa3a5c504c5f51ed1c4d2c8abc4997397deec2 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Tue, 5 Apr 2022 11:25:48 -0400 Subject: [PATCH] Docs: netlify adapter site requirement (#2996) * feat: human-readable error on bad site or base * fix: human-readable error should have 1 config option * docs: update README * chore: changeset * docs: mention localhost for testing via netlify CLI --- .changeset/angry-suits-thank.md | 5 +++++ packages/integrations/netlify/readme.md | 12 +++++++++--- packages/integrations/netlify/src/index.ts | 10 +++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .changeset/angry-suits-thank.md diff --git a/.changeset/angry-suits-thank.md b/.changeset/angry-suits-thank.md new file mode 100644 index 000000000..8c9942730 --- /dev/null +++ b/.changeset/angry-suits-thank.md @@ -0,0 +1,5 @@ +--- +'@astrojs/netlify': patch +--- + +Add human-readable error when a site is not provided in your astro.config diff --git a/packages/integrations/netlify/readme.md b/packages/integrations/netlify/readme.md index 24fdb5187..3e9d7879b 100644 --- a/packages/integrations/netlify/readme.md +++ b/packages/integrations/netlify/readme.md @@ -2,14 +2,18 @@ Deploy your server-side rendered (SSR) Astro app to [Netlify](https://www.netlify.com/). -Use this adapter in your Astro configuration file: +Use this adapter in your Astro configuration file, alongside a valid deployment URL: ```js import { defineConfig } from 'astro/config'; import netlify from '@astrojs/netlify/functions'; export default defineConfig({ - adapter: netlify() + adapter: netlify(), + // Where your Netlify app will be deployed. + // Feel free to use a local URL (i.e. http://localhost:8080) + // to test local builds via the netlify CLI + site: 'https://my-production-url.netlify.app', }); ``` @@ -23,7 +27,9 @@ netlify deploy ## Configuration -The output folder is configuration with the `dist` property when creating the adapter. +### dist + +We build to a `netlify` directory at the base of your project. To change this, use the `dist` option: ```js import { defineConfig } from 'astro/config'; diff --git a/packages/integrations/netlify/src/index.ts b/packages/integrations/netlify/src/index.ts index e7fb72633..181303e33 100644 --- a/packages/integrations/netlify/src/index.ts +++ b/packages/integrations/netlify/src/index.ts @@ -28,7 +28,15 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat } }, 'astro:config:done': ({ config, setAdapter }) => { - setAdapter(getAdapter(new URL(config.base, config.site).toString())); + let site = null; + try { + site = new URL(config.base, config.site); + } catch { + throw new Error( + 'The Netlify adapter requires a deployment URL. Ensure a "site" is specified in your astro.config. If you provided a "base" in your astro.config, ensure it is a valid path.' + ); + } + setAdapter(getAdapter(site.toString())); _config = config; }, 'astro:build:start': async ({ buildConfig }) => {