Skip to content

Commit

Permalink
Docs: netlify adapter site requirement (#2996)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bholmesdev committed Apr 5, 2022
1 parent 50bd14a commit 77aa3a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-suits-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

Add human-readable error when a site is not provided in your astro.config
12 changes: 9 additions & 3 deletions packages/integrations/netlify/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:https://localhost:8080)
// to test local builds via the netlify CLI
site: 'https://my-production-url.netlify.app',
});
```

Expand All @@ -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';
Expand Down
10 changes: 9 additions & 1 deletion packages/integrations/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 77aa3a5

Please sign in to comment.