traefik/webui/src/_services/HttpService.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-09-10 14:40:05 +02:00
import { APP } from '../_helpers/APP'
2019-12-10 17:48:04 +01:00
import { getTotal } from './utils'
2019-09-10 14:40:05 +02:00
const apiBase = '/http'
function getAllRouters (params) {
return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
2019-12-10 17:48:04 +01:00
.then(response => {
const { data = [], headers } = response
const total = getTotal(headers, params)
console.log('Success -> HttpService -> getAllRouters', response, response.data)
return { data, total }
2019-09-10 14:40:05 +02:00
})
}
function getRouterByName (name) {
return APP.api.get(`${apiBase}/routers/${encodeURIComponent(name)}`)
2019-09-10 14:40:05 +02:00
.then(body => {
console.log('Success -> HttpService -> getRouterByName', body.data)
return body.data
})
}
function getAllServices (params) {
return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
2019-12-10 17:48:04 +01:00
.then(response => {
const { data = [], headers } = response
const total = getTotal(headers, params)
console.log('Success -> HttpService -> getAllServices', response.data)
return { data, total }
2019-09-10 14:40:05 +02:00
})
}
function getServiceByName (name) {
return APP.api.get(`${apiBase}/services/${encodeURIComponent(name)}`)
2019-09-10 14:40:05 +02:00
.then(body => {
console.log('Success -> HttpService -> getServiceByName', body.data)
return body.data
})
}
function getAllMiddlewares (params) {
return APP.api.get(`${apiBase}/middlewares?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
2019-12-10 17:48:04 +01:00
.then(response => {
const { data = [], headers } = response
const total = getTotal(headers, params)
console.log('Success -> HttpService -> getAllMiddlewares', response.data)
return { data, total }
2019-09-10 14:40:05 +02:00
})
}
function getMiddlewareByName (name) {
return APP.api.get(`${apiBase}/middlewares/${encodeURIComponent(name)}`)
2019-09-10 14:40:05 +02:00
.then(body => {
console.log('Success -> HttpService -> getMiddlewareByName', body.data)
return body.data
})
}
export default {
getAllRouters,
getRouterByName,
getAllServices,
getServiceByName,
getAllMiddlewares,
getMiddlewareByName
}