Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xinjianzhanghao/page-api-forwarder
A Cloudflare pages script for forwarding your request to API host.
https://github.com/xinjianzhanghao/page-api-forwarder
Last synced: 13 days ago
JSON representation
A Cloudflare pages script for forwarding your request to API host.
- Host: GitHub
- URL: https://github.com/xinjianzhanghao/page-api-forwarder
- Owner: xinjianzhanghao
- Created: 2025-01-15T11:04:47.000Z (27 days ago)
- Default Branch: main
- Last Pushed: 2025-01-22T04:28:06.000Z (21 days ago)
- Last Synced: 2025-01-22T05:23:02.480Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-cloudflare - Page-api-forwarder
README
# Page-api-forwarder
A Cloudflare pages script for forwarding api request.
This project is design to forward API request only.## 1. Description
This is a js script for Cloudflare pages. This script will forward the request you send to it to the api host.
It can help you bypass ip restrictions on some api, and it is fast due to it goes through Cloudflare.## 2. Usage
1. Make sure you have a [Cloudflare](https://cloudflare.com) account. Than go [here](https://pages.cloudflare.com) and click login.
2. Click `new` button and select `Pages`.
3. Click the `upload assets` button and fill in `project name`. The project name is up to you.
4. Click `create project` and drag the zip file into it.
5. Go to the `setting` part of this project and Click the `Add` button next to the `Varible and Secrets` part.
- add this value
|key|values|
|-----------|----------|
|type|text|
|Varible name|`APIHOST`|
|Value|Your Api host name with path should go here.|For more enviromental varible usage, please read [here](#enviromental-varible-explanation)
7. Go to Deployments and reupload the zip file to make sure the enviroment varible work.And now, you can request to `your-project-name.pages.dev` and it should return the response from the api host.
## Enviromental varible explanation
|Name|Avalible values|explanation|example|
|----|----------------|------------|-------|
|`APIHOST`|A url|The api url|`example.com/api`|
|`PROTOCOL`|`HTTP` or `HTTPS`|The protocol of the api,This will overide the one you include at the `APIHOST`. However, if you have a valid value for protocol in the `APIHOST` part, then you don't need to set this varible.|`HTTP`|
|`REQUIREPASSWORD`|`true` or `false`|When this varible is set to `true` and the `PASSWORD` varible has a proper value, then a request header `password` is required. If you don't set this value then it's default to false.|`true`|
|`password`|anything|The password for accessing.|`password`|***Please note that Cloudflare Pages only support HTTPS request.***
## Usage Example
I'll give an example on forwarding [Google AI](https://aistudio.google.com) request. Google AI provides a free API. You can use this project's script to use this API even if you're in country that Gemini API isn't avalible.
1. Make sure you have an [API key](https://aistudio.google.com/apikey).
2. You will need to upload your assets to cloudflare following the steps that I metioned before.
3. Now you can set enviromental varible in the setting part.
|Key|Value|
|---|-----|
|`APIHOST`|`https://generativelanguage.googleapis.com/`|
|`PROTOCOL`|This is optional due to you've set the protocol in the API host part. But however, the value here can be `HTTPS`|
5. Try to run this in the command
```bash
curl "https://yourpageurl.pages.dev/v1beta/models/gemini-1.5-flash:generateContent?key=GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts":[{"text": "Input your message here"}]
}]
}'
```
- replace `yourpageurl.pages.dev` with your page url
- replace `GEMINI_API_KEY` with your [API key](https://aistudio.google.com/apikey)
- replace `Input your message here` to your message
5. Press enter then the request should go through you page function and then reach google.## Contributing
You can open issues or submit your changes.## Support me
__GIVE ME A STAR 😆__
If you think my work helps you, consider support me
- ETH/USDT(ERC20): `0x414E4de402C12de27bB3412e43E3F9B0fBdEBB17`