47 lines
2.5 KiB
Markdown
47 lines
2.5 KiB
Markdown
# Nuxt Toolbox Template
|
|
|
|
## Build Setup
|
|
|
|
```bash
|
|
# install dependencies
|
|
$ npm install
|
|
|
|
# serve with hot reload at localhost:3000
|
|
$ npm run dev
|
|
|
|
# build for production and launch server
|
|
$ npm run build
|
|
$ npm run start
|
|
|
|
# generate static project
|
|
$ npm run generate
|
|
```
|
|
## Redirects
|
|
|
|
In the [`netlify.toml`](./netlify.toml) configuration file there is an example of how to implement redirects. Redirects can be used to do many things from redirecting Single Page Apps more predictably, redirecting based on country/language to leveraging On-Demand Builders for [Distributed Persistant Rendering](https://www.netlify.com/blog/2021/04/14/distributed-persistent-rendering-a-new-jamstack-approach-for-faster-builds/).
|
|
|
|
In the example we'll be using redirects to have a shorter endpoint to Netlify functions. By default, you call a Netlify function when requesting a path like `https://yoursite.netlify.com/.netlify/functions/functionName`. Instead, we'll redirect all calls from a path including `/api` to call on the Netlify functions. So the path will be `https://yoursite.netlify.com/api/functionName`, a lot easier to remember too.
|
|
|
|
|
|
### Example
|
|
```toml
|
|
[[redirects]]
|
|
from = "/api/*"
|
|
to = "/.netlify/functions/:splat"
|
|
status = 200
|
|
force = true
|
|
```
|
|
|
|
First we create a section in the `.toml` for the redirect using `[[redirects]]`. Each redirect should have this line to start the redirect code, and the redirects will be executed in the order they appear in the `.toml` from top to bottom.
|
|
|
|
The bare minimum needed is the `from` and `to`, letting the [CDN](https://www.netlify.com/blog/edge-cdn-serverless-cloud-meaaning) know when a route is requested, the `from`, forward it on to another path, the `to`. In the example, we also added an 'Ok' status code, 200, and set the `force` to true to make sure it _always_ redirects from the `from` path.
|
|
|
|
There are many ways to use redirects. Check out the resouces below to learn more.
|
|
|
|
### Redirect Resources
|
|
|
|
- [Redirect syntax and configuration](https://docs.netlify.com/routing/redirects/#syntax-for-the-netlify-configuration-file)
|
|
- [Redirect options](https://docs.netlify.com/routing/redirects/redirect-options/)
|
|
- [Creating better, more predicatable redirect rules for SPAs](https://www.netlify.com/blog/2020/04/07/creating-better-more-predictable-redirect-rules-for-spas/)
|
|
- [Redirect by country or language](https://docs.netlify.com/routing/redirects/redirect-options/#redirect-by-country-or-language)
|
|
- [On-Demand Builders](https://docs.netlify.com/configure-builds/on-demand-builders/) |