forked from fuma-nama/fumadocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
5 deletions.
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
37 changes: 37 additions & 0 deletions
37
apps/docs/content/docs/ui/(integrations)/openapi/proxy.mdx
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,37 @@ | ||
--- | ||
title: Creating Proxy | ||
description: Avoid CORS problem | ||
--- | ||
|
||
## Introduction | ||
|
||
A proxy server is useful for executing HTTP (`fetch`) requests, as it doesn't have CORS constraints like on the browser. | ||
We can use it for executing HTTP requests on the OpenAPI playground, when the target API endpoints do not have CORS configured correctly. | ||
|
||
<Callout type="warn" title="Warning"> | ||
Do not use this on unreliable sites and API endpoints, the proxy server will | ||
forward all received headers & body, including HTTP-only `Cookies` and | ||
`Authorization` header. | ||
</Callout> | ||
|
||
### Setup | ||
|
||
Create a route handler for proxy server. | ||
|
||
```ts title="/api/proxy/route.ts" | ||
import { openapi } from '@/lib/source'; | ||
|
||
export const { GET, HEAD, PUT, POST, PATCH, DELETE } = openapi.createProxy(); | ||
``` | ||
|
||
> Follow the [Getting Started](/docs/ui/openapi) guide if `openapi` server is not yet configured. | ||
And enable the proxy from `createOpenAPI`. | ||
|
||
```ts title="lib/source.ts" | ||
import { createOpenAPI } from 'fumadocs-openapi/server'; | ||
|
||
export const openapi = createOpenAPI({ | ||
proxyUrl: '/api/proxy', | ||
}); | ||
``` |
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