-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add GitHub Actions workflow to deploy 1000h entry website
- Loading branch information
Showing
3 changed files
with
82 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,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" | ||
|
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,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) | ||
} |
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,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" | ||
|