实现 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

@@ -4,12 +4,22 @@ import { createPinia } from 'pinia'
import App from './App'
import router from './router'
// import { getNacosInstance } from '@shared/lib/nacosInstance';
class Main {
constructor() {
createApp(App)
.use(createPinia())
.use(router)
.mount('#app')
// this.test()
}
async test() {
// 关键通过getNacosInstance获取实例确保已初始化
const nacos = await getNacosInstance();
console.log("product: ", await nacos.find('app-product'))
}
}

View File

@@ -27,10 +27,15 @@ export default class Home extends Vue {
{ id: 3, title: '新闻3' },
]
addCount() {
async created() {
}
async addCount() {
// console.log(await nacos.find('app-product'))
// console.log("ref dom: ", this.refH1)
// this.router.push({ name: 'about' })
// this.route.query
this.counter++
}

View File

@@ -0,0 +1,40 @@
import { nacosServiceManage, RegisterOptions } from "nacos-federation"
import { loadEnv } from 'vite';
console.log("process.env.NODE_ENV: ", process.env.NODE_ENV)
const env = loadEnv(
process.env.NODE_ENV || 'development', // 环境模式development/production
process.cwd() // 项目根目录(.env文件所在位置
);
// 2. 定义配置同步执行无await
const nacosConfig: RegisterOptions = {
serverList: env.VITE_NACOS_ADDRESS,
serviceName: env.VITE_SERVER_NAME,
port: Number(env.VITE_SERVER_PORT),
namespace: env.VITE_NACOS_NAMESPACE || 'public'
};
// 3. 声明实例变量(先不初始化)
let nacosInstance: nacosServiceManage | null = null;
// 4. 提供初始化函数显式调用避免顶级await
export async function initNacosInstance() {
if (nacosInstance) {
return nacosInstance; // 已初始化则直接返回
}
// 首次调用时初始化
nacosInstance = await nacosServiceManage.create(nacosConfig);
console.log('Nacos 实例初始化完成');
return nacosInstance;
}
// 5. 提供获取实例的方法(确保初始化后使用)
export async function getNacosInstance() {
if (!nacosInstance) {
// 若未初始化,先执行初始化
return await initNacosInstance();
}
return nacosInstance;
}

View File

@@ -1 +1,16 @@
/// <reference types="vite/client" />
interface ViteTypeOptions {
// 添加这行代码,你就可以将 ImportMetaEnv 的类型设为严格模式,
// 这样就不允许有未知的键值了。
// strictImportMetaEnv: unknown
}
interface ImportMetaEnv {
// readonly VITE_APP_TITLE: string
// 更多环境变量...
}
interface ImportMeta {
readonly env: ImportMetaEnv
}