Skip to content

Commit

Permalink
feat: Add GitHub Actions workflow to deploy 1000h entry website
Browse files Browse the repository at this point in the history
  • Loading branch information
lyricat committed Jun 24, 2024
1 parent 29ef968 commit 71bd971
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/deploy-1000h-entry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy 1000h entry website

on:
workflow_dispatch:
push:
branches:
- main
paths:
- "entry/**"
pull_request:
branches:
- main
paths:
- "entry/**"

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
# checkout the code
- uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Setup node env
uses: actions/setup-node@master
with:
node-version: "20"

- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# deploy entry/index.js to 1000h-entry according to entry/wrangler.toml
command: publish --env production
workingDirectory: "entry"

26 changes: 26 additions & 0 deletions entry/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

async function handleRequest(request, env) {
const { host, pathname } = new URL(request.url);
// for the root path, forward to Portal
// for other paths, forward to VTP
if (pathname === '/') {
return forwardToPortal(request, env);
} else {
return forwardToVtp(request, env);
}
}

async function renderInternalError(msg) {
return new Response(`Internal Error: ${msg}`, {
status: 500,
headers: { 'Content-Type': 'text/html' }
});
}

async function forwardToVtp(request, env) {
return await env.vtp.fetch(request)
}

async function forwardToPortal(request, env) {
return await env.portal.fetch(request)
}
14 changes: 14 additions & 0 deletions entry/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "1000h-entry"
main = "index.js"
workers_dev = false
compatibility_date = "2023-03-23"

routes = ["next.1000h.org/*"]
services = [
{ binding = "vtp", service = "1000-hours-prod" },
{ binding = "portal", service = "1000h-portal" },
]

[vars]
HOST = "https://next.1000h.org"

0 comments on commit 71bd971

Please sign in to comment.