feat: Add GitHub Actions workflow to deploy 1000h entry website
This commit is contained in:
42
.github/workflows/deploy-1000h-entry.yml
vendored
Normal file
42
.github/workflows/deploy-1000h-entry.yml
vendored
Normal file
@@ -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
entry/index.js
Normal file
26
entry/index.js
Normal file
@@ -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
entry/wrangler.toml
Normal file
14
entry/wrangler.toml
Normal file
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user