Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit bca8875

Browse files
committed
add sub sections about paths and api routes
1 parent 0288ba9 commit bca8875

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docs/architecture/websites.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ websites:
127127
```javascript
128128
async function fetchData() {
129129
// due to apis being served from the same domain thanks to rewrites, no CORS is required
130-
const response = await fetch('/api/hello')
130+
const response = await fetch('/api/main/hello')
131131
const data = await response.json()
132132
console.log(data)
133133
}

docs/websites.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,33 @@ websites:
9494
url: http://localhost:4323
9595
```
9696

97+
## Conflicting Routes
98+
99+
If you have conflicting routes between your API and website or between multiple sub-sites, you can configure the `path` for each website to avoid conflicts.
100+
101+
### Reserved Paths
102+
103+
The following paths are reserved for use by the Nitric framework and cannot be used as website paths:
104+
105+
- `/api` used to rewrite API requests
106+
107+
## API Routes
108+
109+
Nitric automatically serves your API under the `/api` path. You can access your API routes at `https://<your-site>/api/<your-api>/<your-route>`.
110+
111+
By serving your API under the same domain as your website, you avoid CORS issues and can use relative paths to access your API.
112+
113+
Here is an example of calling an API route from your website:
114+
115+
```javascript
116+
async function fetchData() {
117+
// due to apis being served from the same domain thanks to rewrites, no CORS is required
118+
const response = await fetch('/api/main/hello')
119+
const data = await response.json()
120+
console.log(data)
121+
}
122+
```
123+
97124
## Configuration
98125

99126
Here is a breakdown of the configuration options:

0 commit comments

Comments
 (0)