From 71bd971810d99c608a3667ea61bab096b620623d Mon Sep 17 00:00:00 2001 From: Lyric <5h3ll3x@gmail.com> Date: Mon, 24 Jun 2024 17:33:24 +0900 Subject: [PATCH] feat: Add GitHub Actions workflow to deploy 1000h entry website --- .github/workflows/deploy-1000h-entry.yml | 42 ++++++++++++++++++++++++ entry/index.js | 26 +++++++++++++++ entry/wrangler.toml | 14 ++++++++ 3 files changed, 82 insertions(+) create mode 100644 .github/workflows/deploy-1000h-entry.yml create mode 100644 entry/index.js create mode 100644 entry/wrangler.toml diff --git a/.github/workflows/deploy-1000h-entry.yml b/.github/workflows/deploy-1000h-entry.yml new file mode 100644 index 00000000..5a3f7d14 --- /dev/null +++ b/.github/workflows/deploy-1000h-entry.yml @@ -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" + diff --git a/entry/index.js b/entry/index.js new file mode 100644 index 00000000..d1b18805 --- /dev/null +++ b/entry/index.js @@ -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) +} diff --git a/entry/wrangler.toml b/entry/wrangler.toml new file mode 100644 index 00000000..0d306aee --- /dev/null +++ b/entry/wrangler.toml @@ -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" +