封装自动生成 traefik 代理配置的 nodejs 插件代码
This commit is contained in:
38
docker/traefik/src/http/index.js
Normal file
38
docker/traefik/src/http/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const axios = require('axios');
|
||||
const config = require('../config');
|
||||
const {AxiosError} = require("axios");
|
||||
|
||||
class Http {
|
||||
instance = null;
|
||||
|
||||
constructor() {
|
||||
this.instance = axios.create({
|
||||
baseURL: config.nacosApi.baseUrl,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
})
|
||||
|
||||
this.ResponseInterceptor();
|
||||
}
|
||||
|
||||
|
||||
async get(params) {
|
||||
return await this.instance.get(params.url, {
|
||||
params: params.data,
|
||||
});
|
||||
}
|
||||
|
||||
async ResponseInterceptor() {
|
||||
this.instance.interceptors.response.use(
|
||||
(response) => {
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Http
|
||||
Reference in New Issue
Block a user