diff options
author | 2022-04-05 11:25:48 -0400 | |
---|---|---|
committer | 2022-04-05 11:25:48 -0400 | |
commit | 77aa3a5c504c5f51ed1c4d2c8abc4997397deec2 (patch) | |
tree | 8cdc77d35de9f12330f54988b151232bf3fac048 | |
parent | 50bd14aca8a67512b18d4e9981d43007623e20b8 (diff) | |
download | astro-77aa3a5c504c5f51ed1c4d2c8abc4997397deec2.tar.gz astro-77aa3a5c504c5f51ed1c4d2c8abc4997397deec2.tar.zst astro-77aa3a5c504c5f51ed1c4d2c8abc4997397deec2.zip |
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
-rw-r--r-- | .changeset/angry-suits-thank.md | 5 | ||||
-rw-r--r-- | packages/integrations/netlify/readme.md | 12 | ||||
-rw-r--r-- | packages/integrations/netlify/src/index.ts | 10 |
3 files changed, 23 insertions, 4 deletions
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 }) => { |