feat: add Vue 3 admin frontend and integrate with backend like mediabot
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
# PAR Server - 纯 Java Docker 镜像
|
||||
# Phase 1: 最小可用版本
|
||||
# PAR Server - 前后端一体化 Docker 镜像
|
||||
# 参考 mediabot 的多阶段构建方式
|
||||
|
||||
# 构建阶段
|
||||
FROM eclipse-temurin:21-jdk-alpine AS builder
|
||||
# 第一阶段:构建前端
|
||||
FROM 192.168.31.253/library/node:22-alpine AS web-builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY web/package.json web/package-lock.json ./
|
||||
RUN npm ci --ignore-scripts
|
||||
COPY web/ .
|
||||
RUN npm run build
|
||||
|
||||
# 第二阶段:构建后端
|
||||
FROM eclipse-temurin:21-jdk-alpine AS server-builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
@@ -13,21 +22,22 @@ COPY par-core/pom.xml par-core/
|
||||
COPY par-api/pom.xml par-api/
|
||||
|
||||
# 下载依赖(缓存层)
|
||||
RUN --mount=type=cache,target=/root/.m2 \
|
||||
./mvnw dependency:go-offline -B 2>/dev/null || \
|
||||
(apk add --no-cache maven && mvn dependency:go-offline -B)
|
||||
RUN apk add --no-cache maven && \
|
||||
mvn dependency:go-offline -B
|
||||
|
||||
# 复制源码并构建
|
||||
COPY par-common/src par-common/src
|
||||
COPY par-core/src par-core/src
|
||||
COPY par-api/src par-api/src
|
||||
|
||||
RUN apk add --no-cache maven && \
|
||||
mvn clean package -DskipTests -B && \
|
||||
# 将前端构建产物复制到后端静态资源目录
|
||||
COPY --from=web-builder /app/dist par-api/src/main/resources/static
|
||||
|
||||
RUN mvn clean package -DskipTests -B && \
|
||||
mkdir -p target && \
|
||||
cp par-api/target/*.jar target/app.jar
|
||||
|
||||
# 运行阶段
|
||||
# 第三阶段:运行
|
||||
FROM eclipse-temurin:21-jre-alpine
|
||||
|
||||
LABEL maintainer="PAR Team"
|
||||
@@ -42,7 +52,7 @@ WORKDIR /app
|
||||
RUN mkdir -p /app/static/configs && chown -R par:par /app
|
||||
|
||||
# 复制构建产物
|
||||
COPY --from=builder /build/target/app.jar app.jar
|
||||
COPY --from=server-builder /build/target/app.jar app.jar
|
||||
|
||||
USER par
|
||||
|
||||
|
||||
39
par-api/src/main/java/com/par/api/config/WebMvcConfig.java
Normal file
39
par-api/src/main/java/com/par/api/config/WebMvcConfig.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.par.api.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* SPA 路由回退:所有非 API 非静态资源请求返回 index.html
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**")
|
||||
.addResourceLocations("classpath:/static/")
|
||||
.resourceChain(true)
|
||||
.addResolver(new PathResourceResolver() {
|
||||
@Override
|
||||
protected Resource getResource(String resourcePath, Resource location) throws IOException {
|
||||
Resource resource = location.createRelative(resourcePath);
|
||||
if (resource.exists() && resource.isReadable()) {
|
||||
return resource;
|
||||
}
|
||||
// API 路径不处理
|
||||
if (resourcePath.startsWith("api/")) {
|
||||
return null;
|
||||
}
|
||||
// 回退到 index.html(支持前端路由)
|
||||
return new ClassPathResource("static/index.html");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user