This commit is contained in:
hailin 2025-06-25 17:51:30 +08:00
parent 27ea4f576c
commit 452a58a74a
13 changed files with 23 additions and 12 deletions

View File

@ -9,7 +9,7 @@ import { Metadata } from "next"
import { cookies, headers } from "next/headers"
import { redirect } from "next/navigation"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
import { PostgrestError } from '@supabase/supabase-js';
import initTranslations from "@/lib/i18n";

View File

@ -6,7 +6,7 @@ import { ServerRuntime } from "next"
import OpenAI from "openai"
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions.mjs"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export const runtime: ServerRuntime = "edge"

View File

@ -7,7 +7,7 @@ import { createClient } from "@supabase/supabase-js"
import { NextResponse } from "next/server"
import OpenAI from "openai"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
import { generateBgeM3Embedding } from "@/lib/generate-bgem3-embedding"
export async function POST(req: Request) {

View File

@ -14,7 +14,7 @@ import { createClient } from "@supabase/supabase-js"
import { NextResponse } from "next/server"
import OpenAI from "openai"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export async function POST(req: Request) {

View File

@ -5,7 +5,7 @@ import { Database } from "@/supabase/types"
import { createClient } from "@supabase/supabase-js"
import OpenAI from "openai"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export async function POST(request: Request) {

View File

@ -1,7 +1,7 @@
import { Database } from "@/supabase/types"
import { createClient } from "@supabase/supabase-js"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export const runtime = "edge"

View File

@ -1,7 +1,7 @@
import { Database } from "@/supabase/types"
import { createClient } from "@supabase/supabase-js"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export const runtime = "edge"

View File

@ -23,7 +23,7 @@ import React from "react"
import { toast } from "sonner"
import { v4 as uuidv4 } from "uuid"
//import { getRuntimeEnv } from "@/lib/ipconfig"
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
type RetrievedFileItem = Tables<"file_items"> & {

View File

@ -1,4 +1,4 @@
// lib/runtime-env/client.ts
export function getRuntimeEnvClient(key: string): string | undefined {
export function getRuntimeEnvCSR(key: string): string | undefined {
return (window as any).RUNTIME_ENV?.[key]
}

View File

@ -0,0 +1,10 @@
// lib/runtime-env/index.ts
export function getRuntimeEnv(key: string): string | undefined {
if (typeof window === "undefined") {
const { getRuntimeEnvSSR } = require("./server")
return getRuntimeEnvSSR(key)
} else {
const { getRuntimeEnvCSR } = require("./client")
return getRuntimeEnvCSR(key)
}
}

View File

@ -1,7 +1,7 @@
// lib/runtime-env/server.ts
import { headers } from "next/headers"
export function getRuntimeEnvServer(key: string): string | undefined {
export function getRuntimeEnvSSR(key: string): string | undefined {
if (key === "SUPABASE_URL") {
const h = headers()
const proto = h.get("x-forwarded-proto") ?? (h.get("host")?.includes(":443") ? "https" : "http")
@ -9,5 +9,6 @@ export function getRuntimeEnvServer(key: string): string | undefined {
const hostname = rawHost.split(",")[0].split(":")[0].trim()
return `${proto}://${hostname}:8000`
}
return process.env[key]
}

View File

@ -4,7 +4,7 @@ import { VALID_ENV_KEYS } from "@/types/valid-keys"
import { getSupabaseServerClient } from "@/lib/supabase/server"
import { cookies } from "next/headers"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export async function getServerProfile() {

View File

@ -10,7 +10,7 @@
import { createBrowserClient } from "@supabase/ssr"
//import { getRuntimeEnv } from "@/lib/ipconfig"
import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getRuntimeEnv } from "@/lib/runtime-env"
export const createClient = () =>
createBrowserClient(