env error

This commit is contained in:
Tsuki 2025-08-18 00:42:54 +08:00
parent 9cb46de3e1
commit f4c4e8a3b5
7 changed files with 14 additions and 10 deletions

View File

@ -13,7 +13,7 @@ export async function POST(request: NextRequest) {
}
// 转发到后端GraphQL
const response = await fetch(process.env.GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql', {
const response = await fetch(process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@ -22,7 +22,7 @@ export async function POST(request: NextRequest) {
);
}
const client = new GraphQLClient(process.env.GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql');
const client = new GraphQLClient(process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql');
const response: any = await client.request(LOGIN_MUTATION, { username, password });
const jwt = response.login.token;
@ -39,7 +39,6 @@ export async function POST(request: NextRequest) {
} catch (error) {
console.log(process.env.GRAPHQL_BACKEND_URL)
console.error('Login error:', error);
return NextResponse.json(

View File

@ -34,7 +34,7 @@ export async function POST(request: NextRequest) {
const jwt = body.jwt;
const client = new GraphQLClient(process.env.GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql', {
const client = new GraphQLClient(process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql', {
headers: {
'Authorization': `Bearer ${jwt}`
}

View File

@ -12,7 +12,7 @@ const GET_CONFIGS = gql`
`
export async function GET(request: NextRequest) {
const client = new GraphQLClient(process.env.GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql');
const client = new GraphQLClient(process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql');
try {
const data: any = await client.request(GET_CONFIGS);
return NextResponse.json(data.siteConfigs);

View File

@ -164,7 +164,9 @@ export const Timeline: React.FC<Props> = React.memo(({
},
onDateChange: async (date: Date) => {
const datestr = formatInTimeZone(date, 'UTC', 'yyyyMMddHHmmss')
const url_base = process.env.GRAPHQL_BACKEND_URL?.replace('/graphql', '') || 'http://localhost:3050'
const url_base = process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL?.replace('/graphql', '') || 'http://localhost:3050'
// const url_base = "http://45.152.65.37:3050"
const response = await fetch(`${url_base}/api/v1/data/nearest?datetime=${datestr}&area=cn`)
setTimelineTime(date)
@ -243,7 +245,8 @@ export const Timeline: React.FC<Props> = React.memo(({
const date = new Date()
const datestr = formatInTimeZone(date, 'UTC', 'yyyyMMddHHmmss')
const url_base = process.env.GRAPHQL_BACKEND_URL || 'http://localhost:3050'
const url_base = process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL || 'http://localhost:3050'
// const url_base = "http://45.152.65.37:3050"
const response = await fetch(`${url_base}/api/v1/data/nearest?datetime=${datestr}&area=cn`)
if (response.ok) {
const data = await response.json()

View File

@ -58,7 +58,7 @@ export function MapComponent({
useEffect(() => {
if (!isMapReady || !currentDatetime) return;
const utc_time_str = formatInTimeZone(currentDatetime, 'UTC', 'yyyyMMddHHmmss')
const new_url_prefix = process.env.GRAPHQL_BACKEND_URL?.replace('/graphql', '') || 'http://localhost:3050'
const new_url_prefix = process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL?.replace('/graphql', '') || 'http://localhost:3050'
const new_url = `${new_url_prefix}/api/v1/data?datetime=${utc_time_str}&area=cn`
fetchRadarTile(new_url)
}, [currentDatetime, isMapReady])

View File

@ -8,12 +8,14 @@ import { createClient } from 'graphql-ws';
const TOKEN_KEY = 'auth_token';
const httpLink = createHttpLink({
uri: process.env.GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql',
uri: process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL || 'http://localhost:3050/graphql',
// uri: "http://45.152.65.37:3050/graphql"
});
const wsLink = new GraphQLWsLink(createClient({
// url: "ws://127.0.0.1:3050/ws",
url: process.env.GRAPHQL_BACKEND_URL?.replace('/graphql', '/ws')?.replace('http://', 'ws://') || 'ws://localhost:3050/ws',
url: process.env.NEXT_PUBLIC_GRAPHQL_BACKEND_URL?.replace('/graphql', '/ws')?.replace('http://', 'ws://') || 'ws://localhost:3050/ws',
// url: "ws://45.152.65.37:3050/ws"
}));
const authLink = setContext((_, { headers }) => {