43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import axios, { AxiosInstance } from 'axios';
|
|
|
|
export interface IConfigBot {
|
|
token: string;
|
|
dateLifetimeJwt: Date;
|
|
}
|
|
|
|
export interface IBotLink {
|
|
link: string;
|
|
}
|
|
|
|
export class ConfigBotApi {
|
|
private static instance: ConfigBotApi | null = null;
|
|
private httpBotInstance: AxiosInstance;
|
|
|
|
private constructor() {
|
|
const isServer = typeof window === 'undefined';
|
|
const baseURL = isServer
|
|
? 'http://127.0.0.1:3001'
|
|
: process.env.NEXT_PUBLIC_BOT_API;
|
|
this.httpBotInstance = axios.create({
|
|
baseURL,
|
|
headers: {
|
|
'ngrok-skip-browser-warning': 'true',
|
|
},
|
|
});
|
|
}
|
|
|
|
public static getInstance(): ConfigBotApi {
|
|
if (this.instance) return this.instance;
|
|
this.instance = new ConfigBotApi();
|
|
return this.instance;
|
|
}
|
|
|
|
async getConfigBot(): Promise<IConfigBot> {
|
|
return (await this.httpBotInstance.get<IConfigBot>(`/config-bot-data`)).data;
|
|
}
|
|
|
|
async getBotLink(): Promise<IBotLink> {
|
|
return (await this.httpBotInstance.get<IBotLink>(`/link-bot`)).data;
|
|
}
|
|
}
|