From ff1eb745edc321352e3d226cee76a2ee59445c1e Mon Sep 17 00:00:00 2001 From: LazuliKao Date: Tue, 24 Sep 2024 17:53:29 +0800 Subject: [PATCH] fix cors --- astro.config.mts | 11 +++++++++++ nginx.conf | 9 +++++++++ src/pages/freshman/react/join.tsx | 20 ++++++++++++++++++-- src/utils/client.ts | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/astro.config.mts b/astro.config.mts index e4a0909..3d0a3be 100644 --- a/astro.config.mts +++ b/astro.config.mts @@ -225,4 +225,15 @@ export default defineConfig({ experimentalReactChildren: true, }), ], + vite: { + server: { + proxy: { + "/active": { + target: "https://active.nbtca.space", + changeOrigin: true, + rewrite: path => path.replace(/^\/active/, ""), + }, + } + } + } }) diff --git a/nginx.conf b/nginx.conf index 7eb11e5..63e9870 100644 --- a/nginx.conf +++ b/nginx.conf @@ -27,5 +27,14 @@ http { location / { try_files $uri $uri/index.html =404; } + + location /active { + proxy_pass https://active.nbtca.space; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + rewrite ^/active/(.*)$ /$1 break; + } } } \ No newline at end of file diff --git a/src/pages/freshman/react/join.tsx b/src/pages/freshman/react/join.tsx index b898887..3f1aca6 100644 --- a/src/pages/freshman/react/join.tsx +++ b/src/pages/freshman/react/join.tsx @@ -1,12 +1,28 @@ // app/page.tsx import { Button } from "@nextui-org/react" - +import { activeClient } from "../../../utils/client" // import { NextUIProvider } from "@nextui-org/react"; export default function Page() { return (
- +
) } diff --git a/src/utils/client.ts b/src/utils/client.ts index d9f6641..95b4349 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -9,5 +9,5 @@ export const saturdayClient = createClient({ // baseUrl: "https://active.nbtca.space/", // }) export const activeClient = new ApiClient({ - BASE: "https://active.nbtca.space/", + BASE: "/active", })