实现 nacos + traefik,改了很多东西!!!

This commit is contained in:
编码猿
2025-09-22 02:27:53 +08:00
parent e038fdb965
commit dabb91ef1e
71 changed files with 27668 additions and 189 deletions

View File

View File

@@ -0,0 +1,8 @@
# Nacos 配置中心ip:端口
VITE_NACOS_ADDRESS=192.168.31.101:8848
# 注册到 Nacos 的服务名称(微前端模块名称)
VITE_SERVER_NAME=app-shared
# 注册到 Nacos 的端口,也是前端运行的端口
VITE_SERVER_PORT=1333

View File

@@ -14,7 +14,7 @@
},
"dependencies": {
"axios": "^1.12.2",
"nacos-federation": "^1.0.2"
"nacos-federation": "link:../nacos-federation"
},
"devDependencies": {
"@originjs/vite-plugin-federation": "^1.4.1",

View File

@@ -1,5 +1,5 @@
export class HttpConfig {
public static DevBaseUrl: string = "http://127.0.0.1:3000/api"
public static prodBaseUrl: string = "http://127.0.0.1:3000/api/"
public static DevBaseUrl: string = "http://127.0.0.1:3210/api"
public static prodBaseUrl: string = "http://127.0.0.1:3210/api/"
public static apiList: string = ""
}

View File

@@ -1,24 +1,26 @@
import { defineConfig, UserConfig } from 'vite'
import { defineConfig, loadEnv, UserConfig } from 'vite'
import federation from "@originjs/vite-plugin-federation";
import { nacosServiceManage } from "nacos-federation";
// https://vite.dev/config/
export default defineConfig(async (): Promise<UserConfig> => {
new nacosServiceManage({
serverList: '192.168.31.100:8848',
serviceName: 'app-shared',
port: 1333
})
export default defineConfig(async ({ mode }): Promise<UserConfig> => {
const env = loadEnv(mode, process.cwd());
await nacosServiceManage.create({
serverList: env.VITE_NACOS_ADDRESS,
serviceName: env.VITE_SERVER_NAME,
port: Number(env.VITE_SERVER_PORT)
});
return {
base: `/${ env.VITE_SERVER_NAME }/`,
server: {
port: 1333,
port: Number(env.VITE_SERVER_PORT),
host: '0.0.0.0',
strictPort: true,
cors: true
},
plugins: [
federation({
name: 'shared',
name: env.VITE_SERVER_NAME,
exposes: {
"./config": "./src/config/index.ts",
"./infra": "./src/infra/index.ts",
@@ -42,4 +44,4 @@ export default defineConfig(async (): Promise<UserConfig> => {
}
}
}
})
});