Skip to content
Snippets Groups Projects
Commit 73567b57 authored by Alexandros Georgantas's avatar Alexandros Georgantas
Browse files

refactor(server): make service url follow same structure as server url

parent af986db8
No related branches found
No related tags found
3 merge requests!52Docx,!42refactor(server): make service url follow same structure as server url,!17Graphql api
......@@ -18,15 +18,26 @@ const getAccessToken = async (serviceName, renew = false) => {
throw new Error(`service ${serviceName} configuration is undefined `)
}
const { clientId, clientSecret, port, protocol, host } = service
const { clientId, clientSecret, url } = service
if (!clientId) {
throw new Error(`service ${serviceName} clientId is undefined `)
}
if (!clientSecret) {
throw new Error(`service ${serviceName} clientSecret is undefined `)
}
if (!url) {
throw new Error(`service ${serviceName} url is undefined `)
}
const buff = Buffer.from(`${clientId}:${clientSecret}`, 'utf8')
const base64data = buff.toString('base64')
const serviceURL = `${protocol}://${host}${port ? `:${port}` : ''}`
const serviceHealthCheck = await axios({
method: 'get',
url: `${serviceURL}/healthcheck`,
url: `${url}/healthcheck`,
})
const { data: healthCheckData } = serviceHealthCheck
......@@ -43,7 +54,7 @@ const getAccessToken = async (serviceName, renew = false) => {
if (!foundServiceCredential) {
const { data } = await axios({
method: 'post',
url: `${serviceURL}/api/auth`,
url: `${url}/api/auth`,
headers: { authorization: `Basic ${base64data}` },
})
......@@ -60,7 +71,7 @@ const getAccessToken = async (serviceName, renew = false) => {
if (!accessToken || renew) {
const { data } = await axios({
method: 'post',
url: `${serviceURL}/api/auth`,
url: `${url}/api/auth`,
headers: { authorization: `Basic ${base64data}` },
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment