0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

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
This commit is contained in:
Ben Holmes 2022-04-05 11:25:48 -04:00 committed by GitHub
parent 50bd14aca8
commit 77aa3a5c50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---
Add human-readable error when a site is not provided in your astro.config

View file

@ -2,14 +2,18 @@
Deploy your server-side rendered (SSR) Astro app to [Netlify](https://www.netlify.com/). 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 ```js
import { defineConfig } from 'astro/config'; import { defineConfig } from 'astro/config';
import netlify from '@astrojs/netlify/functions'; import netlify from '@astrojs/netlify/functions';
export default defineConfig({ 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 ## 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 ```js
import { defineConfig } from 'astro/config'; import { defineConfig } from 'astro/config';

View file

@ -28,7 +28,15 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat
} }
}, },
'astro:config:done': ({ config, setAdapter }) => { '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; _config = config;
}, },
'astro:build:start': async ({ buildConfig }) => { 'astro:build:start': async ({ buildConfig }) => {