Skip to content

Commit

Permalink
Deploy with bunny.net
Browse files Browse the repository at this point in the history
  • Loading branch information
TibiNonEst committed Nov 20, 2024
1 parent 1f4c336 commit 816e731
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy when pushing on main

on:
push:
branches:
- "main"

permissions:
contents: read
id-token: write

jobs:
publish:
runs-on: ubuntu-latest

name: "Deploy site"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Build site
run: bun run build

- name: Upload files
uses: djang0dev/[email protected]
with:
upload: true
remove: true
storageName: ${{ secrets.BUNNY_STORAGE_NAME }}
storagePassword: ${{ secrets.BUNNY_STORAGE_PASSWORD }}
destination: "tibs.gay/"
sourcePattern: "./dist/**/*.*"
apiKey: ${{ secrets.BUNNY_API_KEY }}
purgePullZone: true
pullZoneId: ${{ secrets.BUNNY_PULL_ZONE_ID }}

- name: Deploy script
uses: BunnyWay/actions/deploy-script@main
with:
script_id: ${{ secrets.BUNNY_SCRIPT_ID }}
deploy_key: ${{ secrets.BUNNY_DEPLOY_KEY }}
file: "script.ts"
16 changes: 16 additions & 0 deletions script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as BunnySDK from "https://esm.sh/@bunny.net/[email protected]";

BunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => {
const url = new URL(request.url);
let path = url.pathname;

if (path == "/") {
path = "/index.html";
}

if (path.startsWith("/_astro") || path == "/index.html") {
return fetch("https://tibs-sites.b-cdn.net/tibs.gay/dist" + path);
}

return Response.redirect("/", 308);
});

0 comments on commit 816e731

Please sign in to comment.