Fix public access mode, introduce loading spinners, package fixes
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const apiHost = typeof window !== 'undefined' && window.location.hostname ? window.location.hostname : '127.0.0.1';
|
||||
const apiClient = axios.create({
|
||||
baseURL: `http://${apiHost}:8000`,
|
||||
const getApiBaseUrl = () => {
|
||||
if (import.meta.env.VITE_API_BASE_URL) {
|
||||
return import.meta.env.VITE_API_BASE_URL;
|
||||
}
|
||||
// Use relative path in browser so requests are routed via Vite proxy or reverse proxy
|
||||
if (typeof window !== 'undefined') {
|
||||
return '';
|
||||
}
|
||||
return 'http://127.0.0.1:8000';
|
||||
};
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: getApiBaseUrl(),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
@@ -86,3 +96,26 @@ export const getHandbookExample = async (
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const generateChallenge = async (
|
||||
prompt: string,
|
||||
language: string,
|
||||
difficulty: string,
|
||||
subject: string
|
||||
) => {
|
||||
const response = await apiClient.post('/challenges/generate', {
|
||||
prompt,
|
||||
language,
|
||||
difficulty,
|
||||
subject,
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const saveChallenge = async (filename: string, markdown: string) => {
|
||||
const response = await apiClient.post('/challenges/save', {
|
||||
filename,
|
||||
markdown,
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user