实现 nacos + traefik,改了很多东西!!!
This commit is contained in:
0
front-end/app-product/.env.development
Normal file
0
front-end/app-product/.env.development
Normal file
21
front-end/app-product/.env.production
Normal file
21
front-end/app-product/.env.production
Normal file
@@ -0,0 +1,21 @@
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
# traefik 网关的地址
|
||||
VITE_TRAEFIK_ADDRESS=192.168.31.101
|
||||
|
||||
# 注册到 Nacos 的服务名称(微前端模块名称
|
||||
VITE_SERVER_NAME=app-product
|
||||
|
||||
# 注册到 Nacos 的端口,也是前端运行的端口
|
||||
VITE_SERVER_PORT=1301
|
||||
|
||||
|
||||
#
|
||||
# 说明:项目要调用哪些 微前端 模块
|
||||
# 格式:VITE_MODEL_XXXX_NAME=微前端模块名称(模块 的 开发者提供)
|
||||
# 作用:通过名称从Nacos配置中心发现模块地址和端口,给 federation 实时加载
|
||||
#
|
||||
|
||||
# shared 共享资源模块
|
||||
VITE_MODEL_SHARED_NAME=app-shared
|
||||
@@ -14,7 +14,7 @@
|
||||
"type-check": "vue-tsc --build"
|
||||
},
|
||||
"dependencies": {
|
||||
"nacos-federation": "^1.0.2",
|
||||
"nacos-federation": "link:../nacos-federation",
|
||||
"pinia": "^3.0.3",
|
||||
"vue": "^3.5.21",
|
||||
"vue-router": "^4.5.1"
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {Product} from "@domains/product/domain/entities/Product.ts";
|
||||
import {ProductType} from "@domains/product/domain/type/ProductType.ts";
|
||||
import {ProductRepository} from "@domains/product/ports/repositories/ProductRepository";
|
||||
import {http} from "shared/infra";
|
||||
import { Product } from "@domains/product/domain/entities/Product.ts";
|
||||
import { ProductType } from "@domains/product/domain/type/ProductType.ts";
|
||||
import { ProductRepository } from "@domains/product/ports/repositories/ProductRepository";
|
||||
import { http } from "shared/infra";
|
||||
import HttpConfig from "../config/HttpConfig";
|
||||
|
||||
|
||||
/**
|
||||
* HTTP商品仓储实现 - 实现商品数据的HTTP访问
|
||||
* 这是基础设施层,负责具体的数据获取实现
|
||||
* 这是基础设施层,负责具体的数据获取实现
|
||||
*/
|
||||
export class HttpProductRepository implements ProductRepository {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
@@ -7,26 +7,30 @@ import { fileURLToPath, URL } from "node:url";
|
||||
import { nacosServiceManage } from "nacos-federation";
|
||||
|
||||
|
||||
export default defineConfig(async () => {
|
||||
const client = new nacosServiceManage({
|
||||
serverList: '192.168.31.100:8848',
|
||||
serviceName: 'app-product',
|
||||
port: 1301
|
||||
})
|
||||
const sharedUrl = await client.find("app-shared")
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
|
||||
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)
|
||||
});
|
||||
// const sharedUrl = await nacos.find(env.VITE_MODEL_SHARED_NAME)
|
||||
|
||||
return {
|
||||
base: `/${ env.VITE_SERVER_NAME }/`,
|
||||
server: {
|
||||
port: 1301,
|
||||
port: Number(env.VITE_SERVER_PORT),
|
||||
host: '0.0.0.0',
|
||||
strictPort: true,
|
||||
cors: true
|
||||
},
|
||||
plugins: [
|
||||
federation({
|
||||
name: 'product',
|
||||
name: env.VITE_SERVER_NAME,
|
||||
remotes: {
|
||||
shared: `${ sharedUrl }/assets/remoteEntry.js`
|
||||
shared: `http://${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_MODEL_SHARED_NAME }/assets/remoteEntry.js`
|
||||
},
|
||||
exposes: { // 暴露给主应用的资源(按功能分组)
|
||||
'./ProductDomain': './src/domains/product/index.ts', // 领域层(实体、服务、接口等)
|
||||
|
||||
Reference in New Issue
Block a user