From 0d7eb8f132c482ba70ed9936d5a1e17b1a81d487 Mon Sep 17 00:00:00 2001 From: Junhui Chen Date: Mon, 14 Jul 2025 21:09:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.config.js | 2 -- dockerfiles/prod.Dockerfile | 1 + lib/server-api-util.ts | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.config.js b/app.config.js index 5c730f6..aee3564 100644 --- a/app.config.js +++ b/app.config.js @@ -1,6 +1,4 @@ // app.config.js -console.log("API_ENDPOINT from process.env:", process.env.API_ENDPOINT); - export default ({ config }) => ({ ...config, extra: { diff --git a/dockerfiles/prod.Dockerfile b/dockerfiles/prod.Dockerfile index 9210a8f..84f7180 100644 --- a/dockerfiles/prod.Dockerfile +++ b/dockerfiles/prod.Dockerfile @@ -7,6 +7,7 @@ RUN npm config set registry http://192.168.31.115:8081/repository/npm/ RUN npm install -g expo-cli && npm install COPY . . RUN cp .env.production .env +ENV API_ENDPOINT=https://api.memorywake.com/api RUN npx expo export -p web # 第二阶段:使用 nginx 作为 Web 服务器 diff --git a/lib/server-api-util.ts b/lib/server-api-util.ts index 7793c1c..5f9d009 100644 --- a/lib/server-api-util.ts +++ b/lib/server-api-util.ts @@ -1,4 +1,5 @@ import { setCredentials } from '@/features/auth/authSlice'; +import Constants from 'expo-constants'; import * as SecureStore from 'expo-secure-store'; import { Platform } from 'react-native'; import Toast from 'react-native-toast-message'; @@ -24,7 +25,7 @@ export interface PagedResult { // 获取.env文件中的变量 -export const API_ENDPOINT = () => process.env.API_ENDPOINT || "http://192.168.31.115:18080/api"; +export const API_ENDPOINT = () => Constants.expoConfig?.extra?.API_ENDPOINT || "http://192.168.31.115:18080/api"; // 更新 access_token 的逻辑 - 用于React组件中 export const useAuthToken = async(message: string | null) => { @@ -140,7 +141,7 @@ export const fetchApi = async ( headers.set('Authorization', `Bearer ${token}`); } - const url = `${API_ENDPOINT()}/v1${path}`; + const url = `${API_ENDPOINT}/v1${path}`; const response = await fetch(url, { ...options, headers,