feat: 接后端线上api
All checks were successful
Dev Deploy / Explore-Gitea-Actions (push) Successful in 24s
Prod Deploy / Explore-Gitea-Actions (push) Successful in 31s

This commit is contained in:
Junhui Chen 2025-07-14 21:02:10 +08:00
parent c4b0dc1432
commit 4913e96586
6 changed files with 36 additions and 5 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
API_ENDPOINT=http://192.168.31.115:18080/api

1
.env.production Normal file
View File

@ -0,0 +1 @@
API_ENDPOINT=https://api.memorywake.com/api

View File

@ -23,12 +23,14 @@ jobs:
run: |
echo "Building the Docker image..."
tag_name=${{ gitea.ref_name }}
docker build -t hub.fairclip.cn/memowake/memowake-front:${tag_name} .
tag_name=$(echo "${{ gitea.ref_name }}" | tr '/' '-')
docker build -t hub.fairclip.cn/memowake/memowake-front:${tag_name} -f dockerfiles/prod.Dockerfile .
docker push hub.fairclip.cn/memowake/memowake-front:${tag_name}
echo "Docker image built successfully!"
- name: Deploy
run: |
echo "Deploying the project..."
tag_name=${{ gitea.ref_name }}
tag_name=$(echo "${{ gitea.ref_name }}" | tr '/' '-')
bash ./scripts/prod_deploy.sh ${tag_name}
echo "Deploy successful!"

9
app.config.js Normal file
View File

@ -0,0 +1,9 @@
// app.config.js
console.log("API_ENDPOINT from process.env:", process.env.API_ENDPOINT);
export default ({ config }) => ({
...config,
extra: {
API_ENDPOINT: process.env.API_ENDPOINT || "http://192.168.31.115:18080/api"
}
});

View File

@ -0,0 +1,17 @@
# 第一阶段:构建 Expo Web 静态文件
FROM docker.fairclip.cn/node:22 AS builder
WORKDIR /app
COPY package.json .
# 设置npm源
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
RUN npx expo export -p web
# 第二阶段:使用 nginx 作为 Web 服务器
FROM docker.fairclip.cn/nginx:1.29-alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@ -23,13 +23,14 @@ export interface PagedResult<T> {
}
// 获取.env文件中的变量
export const API_ENDPOINT = "http://192.168.31.115:18080/api"
export const API_ENDPOINT = () => process.env.API_ENDPOINT || "http://192.168.31.115:18080/api";
// 更新 access_token 的逻辑 - 用于React组件中
export const useAuthToken = async<T>(message: string | null) => {
try {
const { login } = useAuth();
const response = await fetch(`${API_ENDPOINT}/v1/iam/access-token-refresh`);
const response = await fetch(`${API_ENDPOINT()}/v1/iam/access-token-refresh`);
const apiResponse: ApiResponse<T> = await response.json();
// 如果接口报错,页面弹出来错误信息
@ -71,7 +72,7 @@ export const refreshAuthToken = async<T>(message: string | null): Promise<User>
// 退出刷新会重新填充数据
let response;
response = await fetch(`${API_ENDPOINT}/v1/iam/access-token-refresh`, {
response = await fetch(`${API_ENDPOINT()}/v1/iam/access-token-refresh`, {
method: "POST",
body: JSON.stringify({
"refresh_token": cookie,
@ -139,7 +140,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,