Skip to content

Commit

Permalink
Adjust override values for site-url.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonghan committed Aug 8, 2024
1 parent 959a5c8 commit 6091d69
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ FIREBASE_CLIENT_EMAIL=""
FIREBASE_CLIENT_ID=""
FIREBASE_CLIENT_X509_CERT_URL=""

CORS_ALLOW_ORIGIN="https://localhost:3000"
NEXT_PUBLIC_SITE_URL=""
NEXT_PUBLIC_IS_LOCAL_API_SITE_URL="true"

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ jobs:
touch .env
echo "NEXT_PUBLIC_PUSHER_APP_KEY=${{ secrets.NEXT_PUBLIC_PUSHER_APP_KEY }}" >> .env
echo "NEXT_PUBLIC_PUSHER_CLUSTER=${{ secrets.NEXT_PUBLIC_PUSHER_CLUSTER }}" >> .env
echo "SITE_URL=${{ steps.env-set.outputs.siteUrl }}" >> .env
echo "IS_LOCAL_API_SITE_URL=false" >> .env
- name: Build with Next.js
run: |
export RELEASE_VERSION="${{ github.run_id }}-walcron"
export SITE_URL="${{ steps.env-set.outputs.siteUrl }}" && npm run build
npm run build
- name: Upload artifact for GH pages
uses: actions/upload-pages-artifact@v3
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ npm run backstop:approve // Approve the new website ok
1. Install Vercel Cli, with `npm i -g vercel`
2. Pull all the environment into local with `vercel env pull .env.local`. This wil create an environment straight for testing. Incase, there are reset of environment to setup in Vercel, refer to .env file.

## Additional site url

1. CORS_ALLOW_ORIGIN - for whitelisting /api url defined in next.config.js to external apps.
2. SITE_URL - configure for static site to call api.
3. IS_LOCAL_API_SITE_URL - Indicate local api is used. Used for variable domain name.

## Run Github workflows

Project is tied closely with github.
Expand Down Expand Up @@ -139,7 +145,7 @@ NextJS for static generation `output: "export"` in `next.config.js`, requires al
Process.env variable for client side access are required to be defined in .env file (written in merge.yml)

- NEXT_PUBLIC_PUSHER_APP_KEY
- NEXT_PUBLIC_PUSHER_CLUSTER'
- NEXT_PUBLIC_PUSHER_CLUSTER

## Rust Webassembly

Expand Down
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const securityHeaders = [

const apiSecurityHeaders = [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "https://yoonghan.github.io" },
{
key: "Access-Control-Allow-Origin",
value: process.env.CORS_ALLOW_ORIGIN || "localhost",
},
{
key: "Access-Control-Allow-Methods",
value: "GET,DELETE,PATCH,POST,PUT",
Expand Down
9 changes: 2 additions & 7 deletions src/app/projects/checklist/Checklist.jest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ describe("Checklist", () => {
expect(
screen.queryByRole("button", { name: "View More" })
).not.toBeInTheDocument()
expect(fetchMock).toHaveBeenCalledWith(
"https://www.walcron.com/api/cron",
undefined
)
expect(fetchMock).toHaveBeenCalledWith("/api/cron", undefined)
})
})

Expand All @@ -83,9 +80,7 @@ describe("Checklist", () => {
screen.queryByRole("button", { name: "View More" })
).not.toBeInTheDocument()
expect(
screen.getByText(
"Fetch to https://www.walcron.com/api/cron failed, try again later"
)
screen.getByText("Fetch to /api/cron failed, try again later")
).toBeInTheDocument()
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/projects/messenger/config.jest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { pusherAuthEndpoint } from "./config"

describe("Config", () => {
it("should have the correct pusher endpoint", () => {
expect(pusherAuthEndpoint).toBe("https://www.walcron.com/api/pusherauth")
expect(pusherAuthEndpoint).toBe("/api/pusherauth")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { presencePusherApiUrl } from "."

describe("WebrtcVideo", () => {
it("should contain correct pusher api url", () => {
expect(presencePusherApiUrl).toBe("https://www.walcron.com/api/pusherauth")
expect(presencePusherApiUrl).toBe("/api/pusherauth")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("ChatMessageBox", () => {
}

it("should post to the right api url", () => {
expect(apiUrl).toBe("https://www.walcron.com/api/firebase")
expect(apiUrl).toBe("/api/firebase")
})

it("should render component correctly", async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/config/site.jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { setEnv } from "@/__tests__/mocks/setEnv"

describe("root-url", () => {
it("should be default with local website", async () => {
setEnv({ SITE_URL: "", IS_LOCAL_API_SITE_URL: "false" })
const { site } = await import("./site")
expect(site.url).toBe("https://www.walcron.com")
expect(site.apiUrl).toBe("https://www.walcron.com/api")
Expand All @@ -16,7 +17,7 @@ describe("root-url", () => {

it("should getUrl + getApiUrl from env", async () => {
const url = "https://yoonghan.github.io"
setEnv({ SITE_URL: url })
setEnv({ SITE_URL: url, IS_LOCAL_API_SITE_URL: "false" })
const { getApiUrl } = await import("./site")
expect(getApiUrl()).toBe(url + "/api")
})
Expand Down

0 comments on commit 6091d69

Please sign in to comment.