feat: 新增环境变量
All checks were successful
Dev Deploy / Explore-Gitea-Actions (push) Successful in 23s

This commit is contained in:
Junhui Chen 2025-07-14 21:09:19 +08:00
parent 4913e96586
commit 0d7eb8f132
3 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,4 @@
// app.config.js
console.log("API_ENDPOINT from process.env:", process.env.API_ENDPOINT);
export default ({ config }) => ({
...config,
extra: {

View File

@ -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 服务器

View File

@ -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<T> {
// 获取.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<T>(message: string | null) => {
@ -140,7 +141,7 @@ export const fetchApi = async <T>(
headers.set('Authorization', `Bearer ${token}`);
}
const url = `${API_ENDPOINT()}/v1${path}`;
const url = `${API_ENDPOINT}/v1${path}`;
const response = await fetch(url, {
...options,
headers,