mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 10:49:21 +00:00
🐛 fix: proxy requests through the web origin
This commit is contained in:
@@ -33,7 +33,7 @@ services:
|
|||||||
- KUBECONFIG=/home/dev/.kube/config
|
- KUBECONFIG=/home/dev/.kube/config
|
||||||
- DATABASE_URL=postgresql://postgres:postgres@db:5432/minikura?sslmode=disable
|
- DATABASE_URL=postgresql://postgres:postgres@db:5432/minikura?sslmode=disable
|
||||||
- WEB_URL=http://localhost:3001
|
- WEB_URL=http://localhost:3001
|
||||||
- NEXT_PUBLIC_API_URL=http://localhost:3000
|
- API_URL=http://localhost:3000
|
||||||
- KUBERNETES_NAMESPACE=minikura
|
- KUBERNETES_NAMESPACE=minikura
|
||||||
- ENABLE_CRD_REFLECTION=true
|
- ENABLE_CRD_REFLECTION=true
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -6,8 +6,8 @@ DATABASE_URL="postgresql://user:password@localhost:5432/minikura"
|
|||||||
# URL where the web frontend is running (used for CORS)
|
# URL where the web frontend is running (used for CORS)
|
||||||
WEB_URL="http://localhost:3001"
|
WEB_URL="http://localhost:3001"
|
||||||
|
|
||||||
# API URL that the web frontend should connect to
|
# Internal API URL used by the Next.js server and same-origin browser proxy
|
||||||
NEXT_PUBLIC_API_URL="http://localhost:3000"
|
API_URL="http://localhost:3000"
|
||||||
|
|
||||||
# Kubernetes Configuration
|
# Kubernetes Configuration
|
||||||
KUBERNETES_NAMESPACE="minikura"
|
KUBERNETES_NAMESPACE="minikura"
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { betterAuth } from "better-auth";
|
|||||||
import { prismaAdapter } from "better-auth/adapters/prisma";
|
import { prismaAdapter } from "better-auth/adapters/prisma";
|
||||||
import { admin, openAPI } from "better-auth/plugins";
|
import { admin, openAPI } from "better-auth/plugins";
|
||||||
|
|
||||||
|
const webUrl = process.env.WEB_URL || "http://localhost:3001";
|
||||||
|
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: prismaAdapter(prisma, {
|
database: prismaAdapter(prisma, {
|
||||||
provider: "postgresql",
|
provider: "postgresql",
|
||||||
@@ -10,11 +12,11 @@ export const auth = betterAuth({
|
|||||||
}),
|
}),
|
||||||
emailAndPassword: { enabled: true },
|
emailAndPassword: { enabled: true },
|
||||||
plugins: [admin(), openAPI()],
|
plugins: [admin(), openAPI()],
|
||||||
trustedOrigins: [process.env.WEB_URL || "http://localhost:3001"],
|
trustedOrigins: [webUrl],
|
||||||
session: {
|
|
||||||
cookieCache: { enabled: true, maxAge: 60 * 5 },
|
|
||||||
},
|
|
||||||
basePath: "/auth",
|
basePath: "/auth",
|
||||||
|
advanced: {
|
||||||
|
useSecureCookies: webUrl.startsWith("https://"),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Auth = typeof auth;
|
export type Auth = typeof auth;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { redirect } from "next/navigation";
|
|||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000";
|
const apiUrl = process.env.API_URL || "http://localhost:3000";
|
||||||
const api = treaty<App>(apiUrl);
|
const api = treaty<App>(apiUrl);
|
||||||
|
|
||||||
export default async function HomePage() {
|
export default async function HomePage() {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { treaty } from "@elysiajs/eden";
|
import { treaty } from "@elysiajs/eden";
|
||||||
import type { App } from "@minikura/backend";
|
import type { App } from "@minikura/backend";
|
||||||
|
|
||||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000";
|
const baseUrl =
|
||||||
|
typeof window === "undefined"
|
||||||
|
? process.env.API_URL || "http://localhost:3000"
|
||||||
|
: window.location.origin;
|
||||||
|
|
||||||
export const api = treaty<App>(baseUrl, {
|
export const api = treaty<App>(baseUrl, {
|
||||||
fetch: {
|
fetch: {
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import { adminClient } from "better-auth/client/plugins";
|
|||||||
import { createAuthClient } from "better-auth/react";
|
import { createAuthClient } from "better-auth/react";
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
baseURL: process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000",
|
|
||||||
basePath: "/auth",
|
basePath: "/auth",
|
||||||
plugins: [adminClient()],
|
plugins: [adminClient()],
|
||||||
|
fetchOptions: {
|
||||||
|
credentials: "include",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { useSession, signIn, signOut, signUp } = authClient;
|
export const { useSession, signIn, signOut, signUp } = authClient;
|
||||||
|
|||||||
@@ -4,7 +4,21 @@
|
|||||||
* @type {import('next').NextConfig}
|
* @type {import('next').NextConfig}
|
||||||
*/
|
*/
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
/* config options here */
|
async rewrites() {
|
||||||
}
|
const apiUrl = (process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000")
|
||||||
|
.replace(/\/$/, "");
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: "/auth/:path*",
|
||||||
|
destination: `${apiUrl}/auth/:path*`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/api/:path*",
|
||||||
|
destination: `${apiUrl}/api/:path*`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default nextConfig
|
export default nextConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user