Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: netlify adapter site requirement #2996

Merged
merged 5 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://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