first commit
This commit is contained in:
1
app/src/.pydio
Normal file
1
app/src/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
5353715f-ffba-42f8-a416-5d757bcffaec
|
||||
1
app/src/config/.pydio
Normal file
1
app/src/config/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
7a10511f-a00c-487f-8773-a6c2d04b1577
|
||||
37
app/src/config/index.ts
Normal file
37
app/src/config/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
servicesList: [
|
||||
{
|
||||
name: 'gateway',
|
||||
id: 'gateway_id',
|
||||
tags: ['Api 网关'],
|
||||
address: '192.168.31.203',
|
||||
port: 8080
|
||||
},
|
||||
{
|
||||
name: 'user',
|
||||
id: 'user_id',
|
||||
tags: ['user模块', '登录'],
|
||||
address: '192.168.31.203',
|
||||
port: 3002,
|
||||
check: {
|
||||
http: 'http://192.168.31.203:3002/user/health',
|
||||
interval: '10s',
|
||||
timeout: '5s',
|
||||
notes: '服务正常',
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'articles',
|
||||
id: 'articles_id',
|
||||
tags: ['articles模块', '文章'],
|
||||
address: '192.168.31.203',
|
||||
port: 3003,
|
||||
check: {
|
||||
http: 'http://192.168.31.203:3003/articles/health',
|
||||
interval: '10s',
|
||||
timeout: '5s',
|
||||
notes: '服务正常',
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
18
app/src/index.ts
Normal file
18
app/src/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ConsulConf } from "./utils/consul";
|
||||
|
||||
class Run {
|
||||
|
||||
initConsul!: ConsulConf;
|
||||
|
||||
constructor() {
|
||||
// 启动 Consul
|
||||
this.initConsul = new ConsulConf({
|
||||
host: '127.0.0.1',
|
||||
port: "8500",
|
||||
promisify: true, // 是否使用 promise 风格
|
||||
secure: false, // 是否启用https
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
new Run()
|
||||
1
app/src/utils/.pydio
Normal file
1
app/src/utils/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
bfff4b82-ae8b-4738-8507-8f4e4e217a88
|
||||
31
app/src/utils/consul.ts
Normal file
31
app/src/utils/consul.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import Consul, { ConsulOptions } from "consul";
|
||||
import Config from "../config";
|
||||
|
||||
export class ConsulConf {
|
||||
consulInstance!: Consul.Consul;
|
||||
|
||||
constructor(option: ConsulOptions) {
|
||||
this.consulInstance = new Consul(option);
|
||||
|
||||
// 批量注册各个服务
|
||||
Config.servicesList.forEach(async v => {
|
||||
await this.register(v)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务注册
|
||||
*/
|
||||
async register(option: Consul.Agent.Service.RegisterOptions) {
|
||||
let res = await this.consulInstance.agent.service.register(option);
|
||||
console.log("res: === :", res);
|
||||
}
|
||||
|
||||
async list() {
|
||||
return await this.consulInstance.agent.service.list();
|
||||
}
|
||||
|
||||
async deregister(id: string) {
|
||||
return await this.consulInstance.agent.service.deregister(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user