Skip to content

Commit e0c0b7c

Browse files
committed
correctly get data-api url
1 parent fddf00f commit e0c0b7c

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

client-v2/build/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<link rel="apple-touch-icon" href="/MS-icon.png" />
1313
<link rel="manifest" href="/manifest.json" />
1414
<title>Azure SQL Samples Search with AI</title>
15-
<script type="module" crossorigin src="/assets/index-BejuQtoH.js"></script>
15+
<script type="module" crossorigin src="/assets/index-CLifuDVM.js"></script>
1616
<link rel="stylesheet" crossorigin href="/assets/index-D93C6ejO.css">
1717
</head>
1818
<body>

client-v2/src/middleware/ProxyMiddleware.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

client-v2/src/store/slices/SearchSlice.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
2-
import { HttpClient } from '../../utils/httpClient';
2+
import { HttpClient, getDataAPIUrl } from '../../utils/httpClient';
33
import SearchState from './SearchState';
44
import Sample from '../../types/Sample';
55

@@ -8,7 +8,7 @@ const delay = (ms: number | undefined) => new Promise(resolve => setTimeout(reso
88

99
// async search total samples
1010
export const getTotalSamplesAsync = createAsyncThunk<number>('search/getTotalSamples', async () => {
11-
const response = await HttpClient.get(`${import.meta.env.VITE_API_URL}countSamples`, {
11+
const response = await HttpClient.get(`${getDataAPIUrl()}countSamples`, {
1212
withCredentials: false,
1313
headers: {
1414
'Content-Type': 'application/json',
@@ -20,7 +20,7 @@ export const getTotalSamplesAsync = createAsyncThunk<number>('search/getTotalSam
2020

2121
// async list all samples
2222
export const getAllSamplesAsync = createAsyncThunk<Sample[]>('search/getAllSamplesAsync', async () => {
23-
const response = await HttpClient.get(`${import.meta.env.VITE_API_URL}samples`, {
23+
const response = await HttpClient.get(`${getDataAPIUrl()}samples`, {
2424
withCredentials: false,
2525
headers: {
2626
'Content-Type': 'application/json',
@@ -32,7 +32,7 @@ export const getAllSamplesAsync = createAsyncThunk<Sample[]>('search/getAllSampl
3232

3333
// async list latest samples
3434
export const getLatestSamplesAsync = createAsyncThunk<Sample[]>('search/getLatestSamples', async () => {
35-
const response = await HttpClient.get(`${import.meta.env.VITE_API_URL}latestSamples`, {
35+
const response = await HttpClient.get(`${getDataAPIUrl()}latestSamples`, {
3636
withCredentials: false,
3737
headers: {
3838
'Content-Type': 'application/json',
@@ -44,7 +44,7 @@ export const getLatestSamplesAsync = createAsyncThunk<Sample[]>('search/getLates
4444

4545
// async search specific samples
4646
export const searchSamplesAsync = createAsyncThunk<Sample[], string>('search/searchSamplesAsync', async (query: string) => {
47-
const response = await HttpClient.get(`${import.meta.env.VITE_API_URL}findSamples?text=${query}`, {
47+
const response = await HttpClient.get(`${getDataAPIUrl()}findSamples?text=${query}`, {
4848
withCredentials: false,
4949
headers: {
5050
'Content-Type': 'application/json',
@@ -57,7 +57,7 @@ export const searchSamplesAsync = createAsyncThunk<Sample[], string>('search/sea
5757
// delete a sample
5858
export const deleteSampleAsync = createAsyncThunk<number, string>('search/deleteSampleAsync', async (id: string) => {
5959
await delay(1000).then(async () => { // for better user experience
60-
await HttpClient.delete(`${import.meta.env.VITE_API_URL}deleteSample`, {
60+
await HttpClient.delete(`${getDataAPIUrl()}deleteSample`, {
6161
data: { id: id, url: null },
6262
withCredentials: false,
6363
headers: {
@@ -72,7 +72,7 @@ export const deleteSampleAsync = createAsyncThunk<number, string>('search/delete
7272

7373
// get the details
7474
export const getSampleDetailsAsync = createAsyncThunk<Sample, string>('search/getSampleDetailsAsync', async (id: string) => {
75-
const response = await HttpClient.post(`${import.meta.env.VITE_API_URL}sampleDetails`, { id: id, url: null }, {
75+
const response = await HttpClient.post(`${getDataAPIUrl()}sampleDetails`, { id: id, url: null }, {
7676
// withCredentials: false,
7777
headers: {
7878
'Content-Type': 'application/json',
@@ -85,7 +85,7 @@ export const getSampleDetailsAsync = createAsyncThunk<Sample, string>('search/ge
8585

8686
// create a sample
8787
export const createSampleAsync = createAsyncThunk<number, string>('search/createSampleAsync', async (payload: string) => {
88-
const response = await HttpClient.post(`${import.meta.env.VITE_API_URL}createSample`, { payload: payload }, {
88+
const response = await HttpClient.post(`${getDataAPIUrl()}createSample`, { payload: payload }, {
8989
// withCredentials: false,
9090
headers: {
9191
'Content-Type': 'application/json',

client-v2/src/utils/httpClient.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ export class HttpClient {
103103
}
104104
}
105105

106+
function getDataAPIUrl() {
107+
if (import.meta.env.VITE_API_URL) {
108+
return import.meta.env.VITE_API_URL;
109+
}
110+
return './data-api/rest/';
111+
}
112+
106113
// Export the retry function for custom use cases
107-
export { withRetry, DEFAULT_RETRY_CONFIG };
114+
export { getDataAPIUrl, withRetry, DEFAULT_RETRY_CONFIG };
108115
export type { RetryConfig };

0 commit comments

Comments
 (0)