feat:环境变量处理

This commit is contained in:
MatrixSeven
2025-08-01 19:38:59 +08:00
parent 664fe2fdaa
commit dbfdbf0116
15 changed files with 396 additions and 1035 deletions

View File

@@ -1,13 +1,15 @@
import { NextRequest, NextResponse } from 'next/server';
const GO_BACKEND_URL = process.env.GO_BACKEND_URL || 'http://localhost:8080';
import { getBackendUrl } from '@/lib/config';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
// 使用配置管理获取后端URL
const backendUrl = getBackendUrl('/api/create-room');
// 转发请求到Go后端
const response = await fetch(`${GO_BACKEND_URL}/api/create-room`, {
const response = await fetch(backendUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { getBackendUrl } from '@/lib/config';
export async function POST(req: NextRequest) {
try {
@@ -13,7 +14,7 @@ export async function POST(req: NextRequest) {
}
// 调用后端API创建文字传输房间
const response = await fetch('http://localhost:8080/api/create-text-room', {
const response = await fetch(getBackendUrl('/api/create-text-room'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@@ -1,6 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
const GO_BACKEND_URL = process.env.GO_BACKEND_URL || 'http://localhost:8080';
import { getBackendUrl } from '@/lib/config';
export async function GET(request: NextRequest) {
try {
@@ -15,7 +14,7 @@ export async function GET(request: NextRequest) {
}
// 转发请求到Go后端
const response = await fetch(`${GO_BACKEND_URL}/api/room-info?code=${code}`, {
const response = await fetch(getBackendUrl(`/api/room-info?code=${code}`), {
method: 'GET',
headers: {
'Content-Type': 'application/json',