mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-07 01:02:55 +08:00
4b24472106
* docs(i18n): translate batch 1 * docs(i18n): translate batch 2 * docs(i18n): translate batch 3 (20 files) - openapi/: app, share - faq/: all 8 files - use-cases/: index, external-integration (5 files), app-cases (4 files) Translated using North American style with natural, concise language. Preserved MDX syntax, code blocks, images, and component imports. * docs(i18n): translate protocol docs * docs(i18n): translate introduction docs (part 1) * docs(i18n): translate use-cases docs * docs(i18n): translate introduction docs (part 2 - batch 1) * docs(i18n): translate final 9 files * fix(i18n): fix YAML and MDX syntax errors in translated files - Add quotes to description with colon in submit_application_template.en.mdx - Remove duplicate Chinese content in translate-subtitle-using-gpt.en.mdx - Fix unclosed details tag issue * docs(i18n): translate all meta.json navigation files * fix(i18n): translate Chinese separators in meta.en.json files * translate * translate * i18n --------- Co-authored-by: archer <archer@archerdeMac-mini.local> Co-authored-by: archer <545436317@qq.com>
51 lines
1.2 KiB
Plaintext
51 lines
1.2 KiB
Plaintext
---
|
|
title: Cloudflare Worker Proxy
|
|
description: Use Cloudflare Worker as a Proxy
|
|
---
|
|
|
|
[Reference tutorial by "不做了睡觉"](https://gravel-twister-d32.notion.site/FastGPT-API-ba7bb261d5fd4fd9bbb2f0607dacdc9e)
|
|
|
|
**Workers configuration file**
|
|
|
|
```js
|
|
const TELEGRAPH_URL = 'https://api.openai.com';
|
|
|
|
addEventListener('fetch', (event) => {
|
|
event.respondWith(handleRequest(event.request));
|
|
});
|
|
|
|
async function handleRequest(request) {
|
|
// Security check
|
|
if (request.headers.get('auth') !== 'auth_code') {
|
|
return new Response('UnAuthorization', { status: 403 });
|
|
}
|
|
|
|
const url = new URL(request.url);
|
|
url.host = TELEGRAPH_URL.replace(/^https?:\/\//, '');
|
|
|
|
const modifiedRequest = new Request(url.toString(), {
|
|
headers: request.headers,
|
|
method: request.method,
|
|
body: request.body,
|
|
redirect: 'follow'
|
|
});
|
|
|
|
const response = await fetch(modifiedRequest);
|
|
const modifiedResponse = new Response(response.body, response);
|
|
|
|
// Add CORS headers
|
|
modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');
|
|
|
|
return modifiedResponse;
|
|
}
|
|
```
|
|
|
|
**Update FastGPT environment variables**
|
|
|
|
> Don't forget to include v1!
|
|
|
|
```bash
|
|
OPENAI_BASE_URL=https://xxxxxx/v1
|
|
OPENAI_BASE_URL_AUTH=auth_code
|
|
```
|