-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(node): Add recipe for deploying serverless functions to Netlify (#…
- Loading branch information
1 parent
807884c
commit 9e12953
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
docs/shared/recipes/deployment/node-serverless-functions-netlify.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Deploying Node.js serverless functions to Netlify | ||
|
||
Deploying Node.js serverless functions to Netlify involes a few steps: | ||
|
||
## Creating the project | ||
|
||
For new workspaces you can create a Nx workspace with serverless function with one command: | ||
|
||
```shell | ||
npx create-nx-workspace@latest my-functions \ | ||
--preset=@nrwl/netlify \ | ||
--site=my-site \ # Site ID or name to deploy the functions | ||
``` | ||
|
||
## Configuring existing projects | ||
|
||
**Skip this step if you are not configuring an existing project.** | ||
|
||
You will need to install `@nrwl/netlify` if you haven't already. | ||
|
||
{% tabs %} | ||
{% tab label="npm" %} | ||
|
||
```shell | ||
npm i -D @nrwl/netlify | ||
``` | ||
|
||
{% /tab %} | ||
{% tab label="yarn" %} | ||
|
||
```shell | ||
yarn add -D @nrwl/netlify | ||
``` | ||
|
||
{% /tab %} | ||
{% tab label="pnpm" %} | ||
|
||
```shell | ||
pnpm add -D @nrwl/netlify | ||
``` | ||
|
||
{% /tab %} | ||
{% /tabs %} | ||
|
||
- Add serverless configuration by running the following command: | ||
|
||
```shell | ||
nx generate @nrwl/netlify:setup-serverless | ||
``` | ||
|
||
- Create a new netlify serverless project with: | ||
|
||
```shell | ||
nx generate @nrwl/netlfiy:serverless | ||
``` | ||
|
||
This will do a few things: | ||
|
||
1. Create a new serverless function in `src/functions`. | ||
2. Add the `netlify.toml` in the root of the project | ||
3. Update your `project.json` to have 2 new targets `dev` & `deploy`. | ||
|
||
## Configure your Netlify deploy settings | ||
|
||
If you **do not** have a _site_ setup within your workspace, go inside the Netlify dashboard, and create/use an existing site where your serverless functions will be deployed. | ||
|
||
In your `project.json` you can update your deploy site by going to the `deploy` target adding `--site=my-site-name-or-id` replace **my-site-name-or-id** to what you have in your Netlify dashboard. | ||
|
||
It should look similar to: | ||
|
||
```json | ||
"deploy": { | ||
"dependsOn": ["lint"], | ||
"command": "npx netlify deploy --prod-if-unlocked --site=my-site" | ||
} | ||
``` | ||
|
||
## Deployment | ||
|
||
To view your functions locally you run: | ||
|
||
```shell | ||
nx serve | ||
``` | ||
|
||
Inside your `netlify.toml` your functions _path_ should be already configured. | ||
To deploy them to Netlify you would run: | ||
|
||
```shell | ||
nx deploy | ||
``` | ||
|
||
The netlify CLI will output the link where you functions can be accessed. You can either click that link or open your browser and navigate to it! |
9e12953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-nrwl.vercel.app