This commit is contained in:
parent
27ea4f576c
commit
452a58a74a
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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"> & {
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue