# netlify

## Introduction

Netlify is an extremely popular static website host, following the JAM stack principle. While their main focus is to build and host static content, they have released a lambda service called functions which allows you to run endpoints that has the same signature as AWS Lambda functions. The benefit of using Netlify is having quick and automatic deployments which propagate through Netlify's CDN all triggered with a simple `git push`.

**NOTE: Netlify does not support functions in subdirectories! This means if you have a route `routes/hello/world.js`, it will not work.** See this [GitHub issue](https://github.com/netlify/netlify-lambda/issues/90) for more details.

## Setup

This guide assumes that you have already set up a Netlify account, and a GitHub repository.

Before you can deploy, you must first populate your git repository. Follow the [getting started](https://github.com/ludicrousxyz/light/tree/207804d2e826e1f45ff0c63ba7b17f61c563bd82/guides/getting-started/README.md) guide to build you initial app, and verify everything is working with `npm run dev`. Once you have that set up, add a `netlify.toml` file that contains the path to the routes directory.

```
[build]
  command = "npm install"
  functions = "routes"
```

That's all you need in terms of code! Now head over to Netlify's website and click the "New Site From Git" button. Follow the steps to connect your GitHub account to Netlify and add your GitHub repo. Once you get to the final step, just leave the pre-filled data as is and press deploy. **This will deploy successfully, BUT your endpoints will not work.** Why is that? Well, light does not know which environment it neeeds to transform to. To set this up, open the settings page (on the top), go to the "Build and Deploy" section in the sidebar, and click "Environments" in the sidebar. Click "Edit Variables", and add a new environment variable which sets `LIGHT_ENVIRONMENT` to `netlify`. The end result should look like this.

![environment settings in netlify](https://github.com/ludicrousxyz/light/tree/207804d2e826e1f45ff0c63ba7b17f61c563bd82/static/images/screenshots/netlify/environment.png)

Press save to save your changes. Finally, to update your function to use this environment variable, you must go to the "Deploys" page at the top, and press "Trigger Deploy", and "Deploy Site".

![trigger deploy](https://github.com/ludicrousxyz/light/tree/207804d2e826e1f45ff0c63ba7b17f61c563bd82/static/images/screenshots/netlify/trigger-deploy.png)

That's it! Your functions will now be deployed and ready to use. To see an example of a hosted endpoint, visit [light-example.netlify.com/.netlify/functions/index](https://light-example.netlify.com/.netlify/functions/index). The source code is available on [GitHub](https://github.com/light-examples/netlify).

**NOTE**: Netlify uses the file system as the router, so you will not be able to define custom paths with the `path` flag, and routes such as `index` will not be mapped to `/`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.light.js.org/guides/deployments/netlify.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
