Skip to content

Commit

Permalink
add /question-builder/ baseURL env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed Jun 21, 2023
1 parent f0194d8 commit 788176e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/API/ara.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import utils from './utils';
import { api } from './baseUrlProxy';

const baseRoutes = {
/**
Expand All @@ -8,7 +8,7 @@ const baseRoutes = {
*/
async getQuickAnswer(ara, message) {
try {
const response = await axios.post(`/api/quick_answer/?ara=${ara}`, message);
const response = await api.post(`/api/quick_answer/?ara=${ara}`, message);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand All @@ -30,7 +30,7 @@ const baseRoutes = {
config.headers.Authorization = `Bearer ${token}`;
}
try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (e) {
return utils.handleAxiosError(e);
Expand Down
6 changes: 6 additions & 0 deletions src/API/baseUrlProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import axios from 'axios';

// eslint-disable-next-line import/prefer-default-export
export const api = axios.create({
baseURL: process.env.BASE_URL,
});
5 changes: 2 additions & 3 deletions src/API/biolink.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';

import utils from './utils';
import { api } from './baseUrlProxy';

const routes = {
/**
Expand All @@ -9,7 +8,7 @@ const routes = {
async getModelSpecification() {
let response;
try {
response = await axios.get('/api/biolink');
response = await api.get('/api/biolink');
} catch (error) {
return utils.handleAxiosError(error);
}
Expand Down
3 changes: 2 additions & 1 deletion src/API/nameResolver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import utils from './utils';
import { api } from './baseUrlProxy';

const baseRoutes = {
/**
Expand All @@ -17,7 +18,7 @@ const baseRoutes = {
cancelToken: cancel,
};
try {
const response = await axios.post('/api/name_resolver', {}, config);
const response = await api.post('/api/name_resolver', {}, config);
return response.data;
} catch (error) {
if (axios.isCancel(error)) {
Expand Down
3 changes: 2 additions & 1 deletion src/API/nodeNormalization.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import utils from './utils';
import { api } from './baseUrlProxy';

const baseRoutes = {
/**
Expand All @@ -11,7 +12,7 @@ const baseRoutes = {
cancelToken: cancel,
};
try {
const response = await axios.post('/api/node_norm', curies, config);
const response = await api.post('/api/node_norm', curies, config);
return response.data;
} catch (error) {
if (axios.isCancel(error)) {
Expand Down
4 changes: 2 additions & 2 deletions src/API/queryDispatcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import utils from './utils';
import { api } from './baseUrlProxy';

const baseRoutes = {
/**
Expand All @@ -20,7 +20,7 @@ const baseRoutes = {
};
config.headers.Authorization = token;
try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand Down
13 changes: 6 additions & 7 deletions src/API/robokache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';

import utils from './utils';
import { api } from './baseUrlProxy';

// Base request method for all endpoints
async function baseRequest(path, method, body, token) {
Expand All @@ -19,7 +18,7 @@ async function baseRequest(path, method, body, token) {
}

try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand Down Expand Up @@ -53,7 +52,7 @@ const routes = {
config.headers.Authorization = `Bearer ${token}`;
}
try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand All @@ -71,7 +70,7 @@ const routes = {
config.headers.Authorization = `Bearer ${token}`;
}
try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand All @@ -88,7 +87,7 @@ const routes = {
};
config.headers.Authorization = `Bearer ${token}`;
try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand All @@ -104,7 +103,7 @@ const routes = {
};
config.headers.Authorization = `Bearer ${token}`;
try {
const response = await axios(config);
const response = await api(config);
return response.data;
} catch (error) {
return utils.handleAxiosError(error);
Expand Down
8 changes: 4 additions & 4 deletions tests/common/mocks/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import biolink from '&/biolink_model.json';
import test_message from '&/test_message.json';

const handlers = [
rest.get('/api/biolink', (req, res, ctx) => res(
rest.get(`${process.env.BASE_URL || ''}/api/biolink`, (req, res, ctx) => res(
ctx.json(biolink),
)),
rest.post('/api/node_norm', (req, res, ctx) => {
rest.post(`${process.env.BASE_URL || ''}/api/node_norm`, (req, res, ctx) => {
const curie = req.body.curies[0];
return res(
ctx.json({
Expand All @@ -21,15 +21,15 @@ const handlers = [
}),
);
}),
rest.post('/api/name_resolver', (req, res, ctx) => {
rest.post(`${process.env.BASE_URL || ''}/api/name_resolver`, (req, res, ctx) => {
const curie = req.url.searchParams.get('string');
return res(
ctx.json({
[curie]: {},
}),
);
}),
rest.post('/api/quick_answer', (req, res, ctx) => res(
rest.post(`${process.env.BASE_URL || ''}/api/quick_answer`, (req, res, ctx) => res(
ctx.json(test_message),
)),
];
Expand Down

0 comments on commit 788176e

Please sign in to comment.