-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cloudflare worker automation scripts
- Loading branch information
1 parent
7d8bd5c
commit 1a89496
Showing
3 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Deploy Worker to Cloudflare | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: worker | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Wrangler | ||
run: npm install -g wrangler | ||
|
||
- name: Publish the Worker | ||
run: wrangler publish --env production | ||
env: | ||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }} |
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,27 @@ | ||
addEventListener('fetch', event => { | ||
event.respondWith(handleRequest(event.request)); | ||
}); | ||
|
||
async function handleRequest(request) { | ||
// Modify the request URL | ||
const url = new URL(request.url); | ||
url.protocol = 'http:'; | ||
url.hostname = 'host.btiplatform.com'; | ||
url.port = '8080'; | ||
|
||
// Fetch the data from the modified URL | ||
const response = await fetch(url.toString(), request); | ||
|
||
// Create a new response with CORS headers | ||
const newHeaders = new Headers(response.headers); | ||
newHeaders.set("Access-Control-Allow-Origin", "*"); // Adjust as needed for security | ||
newHeaders.set("Access-Control-Allow-Methods", "GET, POST"); | ||
newHeaders.set("Access-Control-Allow-Headers", "Content-Type, Authorization"); | ||
|
||
// Return the response with the new headers | ||
return new Response(response.body, { | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: newHeaders | ||
}); | ||
} |
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,8 @@ | ||
name = "api" | ||
|
||
[site] | ||
bucket = "./worker" # Path to your worker code | ||
|
||
[env.production] | ||
# The account_id is set through an environment variable in the GitHub Actions workflow | ||
account_id = "$CLOUDFLARE_ACCOUNT_ID" |