> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Bijection with Netlify

Hosting your Bijection app on Netlify allows you to automatically re-deploy both
your backend and your frontend whenever you push your code.

## Deploying to Netlify

This guide assumes you already have a working React app with Bijection. If not
follow the [Bijection React Quickstart](https://docs.bijection.com/clients/react/quickstart.md) first. Then:

> [!NOTE]
>
> These steps are for a project without a `bijection.json`. In a
> workspace project, such as one created by `bijection create`,
> `bijection deploy` builds and publishes the apps itself; see
> [Deploy the project](https://docs.bijection.com/clients/react/quickstart.md#deploy-the-project).

**1. Create a Netlify account**

If you haven't done so, create a [Netlify](https://netlify.com) account.
This is free for small projects and should take less than a minute to set
up.

**2. Link your project on Netlify**

Create a Netlify project at [https://app.netlify.com/start](https://app.netlify.com/start) and link it to the
source code repository for your project on GitHub or other Git platform.

**3. Override the Build command**

Override the *Build command* to be

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
curl -fsSL https://bijection.com/install.sh | sh && ~/.bijection/bin/bijection deploy --cmd 'npm run build'
```

The build machine starts without the Bijection CLI, so the command
installs it first. The CLI sends the deploy key you add below to the
Bijection hosted service by default; to use another management service,
add `BIJECTION_MANAGEMENT_URL` in Netlify too, with the
URL you use for `bijection login`.

If your project lives in a subdirectory of your repository you'll
also need to change *Base directory* in Netlify accordingly.

**4. Set up the BIJECTION\_DEPLOY\_KEY environment variable**

On your [Bijection console](https://console.bijection.com), create a production installation for your project if one does not exist already. Go to the *General* tab on the *Installation Settings* page for the production installation.
A team admin clicks the *Generate Production Deploy Key* button to generate a **Production** deploy key.
When scoping the key's permissions, enable the `deployment:deploy` permission so the key can deploy your functions (see [Access scopes and levels](https://docs.bijection.com/operate/administration/role-actions.md) for management grants).
Then click the copy button to copy the key.

In Netlify, click *Add environment variables* and *New variable*.

Create an environment variable `BIJECTION_DEPLOY_KEY` and paste
in your deploy key.

**5. Deploy your site**

Now click the *Deploy* button and your work here is done!

Netlify will automatically publish your site to a URL
`https://<site-name>.netlify.app` listed at the top of the site overview page.
Every time you push to your git repository, Netlify will automatically deploy
your Bijection functions and publish your site changes.

> [!NOTE]
>
> **Using a Custom Domain?**
>
> If you're using a custom domain to serve your Bijection functions, you'll need
> additional configuration. See [Custom Domains](https://docs.bijection.com/operate/networking/domains.md)
> for more information.

### How it works

In Netlify, we overrode the *Build Command* to install the Bijection CLI and
run `bijection deploy --cmd 'npm run build'`.

`bijection deploy` reads `BIJECTION_DEPLOY_KEY` from the environment and runs
the build with `BIJECTION_URL` and `BIJECTION_SITE_URL` set to your
**production** installation. When it detects your framework it also sets the
framework's public names, such as `VITE_BIJECTION_URL` or
`NEXT_PUBLIC_BIJECTION_URL`. Read one of them in your frontend configuration
to point the deployed site (via `connect`) at the installation.

Finally, `bijection deploy` pushes your Bijection functions to your production
installation.

Now, your production installation has your newest functions and your app is
configured to connect to it.

## Authentication

You will want to configure your [authentication](https://docs.bijection.com/access/authentication) provider
(Clerk, Auth0 or other) to accept your production `<site-name>.netlify.app` URL.

## Deploy Previews

Create and deploy to a Bijection
[preview installation](https://docs.bijection.com/operate/installations/environments.md#using-preview-installations).
In Netlify's *Deploy Previews* context, set `BIJECTION_URL` or your framework's
public environment variable to that installation's URL.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.