Skip to content

Commit

Permalink
Rename apiInstance to axiosInstance and remove base URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jun 26, 2024
1 parent 4fa4bfa commit 516b5f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/api.ts → src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import JSONbig from 'json-big'

// Defines the API instance in Axios with special handling for big integers.
export const apiInstance = axios.create({
const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_API_URL,
timeout: 5000,
transformResponse: [
Expand All @@ -20,3 +20,5 @@ export const apiInstance = axios.create({
}
]
})

export default axiosInstance
12 changes: 6 additions & 6 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import TextInput from '@/components/TextInput.vue'
import DropdownSelect from '@/components/DropdownSelect.vue';
import { useRouter } from 'vue-router';
import { useAppStore } from '@/store/app'
import { apiInstance } from '@/api'
import axiosInstance from '@/axios'
// get the application state store and router
const store = useAppStore()
Expand Down Expand Up @@ -164,7 +164,7 @@ async function submit_form(this: any) {
[formData.value.ra, formData.value.dec] = formData.value.coords ? formData.value.coords.split(',') : ["", ""]
console.log('submitting', formData.value)
await apiInstance.post('/query/main',
await axiosInstance.post('/query/main',
formData.value, {headers: {'Content-Type': 'application/json'}})
.then((response) => {
// handle the initial response
Expand Down Expand Up @@ -235,9 +235,9 @@ onMounted(() => {
// set up API call endpoints
let endpoints = [
import.meta.env.VITE_API_URL + `/query/list/cartons`,
import.meta.env.VITE_API_URL + `/query/list/programs`,
import.meta.env.VITE_API_URL + `/query/list/program-map`
`/query/list/cartons`,
`/query/list/programs`,
`/query/list/program-map`
]
// check if the store already has data saved
Expand All @@ -247,7 +247,7 @@ onMounted(() => {
}
// await the promises and cache the results in the store
Promise.all(endpoints.map((endpoint) => apiInstance.get(endpoint)))
Promise.all(endpoints.map((endpoint) => axiosInstance.get(endpoint)))
.then(([{data: carts}, {data: progs}, {data: progmap}] )=> {
console.log({ carts, progs, progmap })
store.store_cartons(carts, progs, progmap)
Expand Down
14 changes: 7 additions & 7 deletions src/views/Target.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ import AladinLite from '@/components/AladinLite.vue'
import TargetResolver from '@/components/TargetResolver.vue'
import DataDownload from '@/components/DataDownload.vue'
import { apiInstance } from '@/api'
import axiosInstance from '@/axios'
// get the application state store and router
const store = useAppStore()
Expand Down Expand Up @@ -165,14 +165,14 @@ async function get_target_info() {
// set up API call endpoints
let endpoints = [
import.meta.env.VITE_API_URL + `/target/ids/${sdss_id}?release=${rel}`,
import.meta.env.VITE_API_URL + `/target/cartons/${sdss_id}?release=${rel}`,
import.meta.env.VITE_API_URL + `/target/catalogs/${sdss_id}?release=${rel}`,
import.meta.env.VITE_API_URL + `/target/pipelines/${sdss_id}?release=${rel}`
`/target/ids/${sdss_id}?release=${rel}`,
`/target/cartons/${sdss_id}?release=${rel}`,
`/target/catalogs/${sdss_id}?release=${rel}`,
`/target/pipelines/${sdss_id}?release=${rel}`
]
// await the promises
await Promise.all(endpoints.map((endpoint) => apiInstance.get(endpoint)))
await Promise.all(endpoints.map((endpoint) => axiosInstance.get(endpoint)))
.then(([{data: target}, {data: cartons}, {data: catalogs}, {data: pipes}] )=> {
console.log({ target, cartons, catalogs, pipes })
loading.value = false
Expand Down Expand Up @@ -210,7 +210,7 @@ async function get_db_info() {
return
}
await apiInstance.get(import.meta.env.VITE_API_URL + '/info/database')
await axiosInstance.get('/info/database')
.then((response) => {
console.log('db info', response.data)
// store the db metadata
Expand Down

0 comments on commit 516b5f4

Please sign in to comment.