mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: remove domain isolation scripts and related components for cleanup
This commit is contained in:
parent
98b833c8ba
commit
f46f4dd552
13 changed files with 73 additions and 837 deletions
|
|
@ -1,59 +0,0 @@
|
|||
import { getApiUrl } from './runtimeConfig';
|
||||
|
||||
/**
|
||||
* Creates an API client that uses runtime configuration
|
||||
* @returns {Object} API client object with fetch method
|
||||
*/
|
||||
export function createApiClient() {
|
||||
return {
|
||||
/**
|
||||
* Fetch data from the API with the correct runtime URL
|
||||
* @param {string} path - API path to fetch from
|
||||
* @param {Object} options - Fetch options
|
||||
* @returns {Promise<any>} - JSON response
|
||||
*/
|
||||
fetch: async (path, options = {}) => {
|
||||
const url = getApiUrl(path);
|
||||
console.log(`[API] Fetching from: ${url}`);
|
||||
|
||||
const response = await fetch(url, options);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Post data to the API with the correct runtime URL
|
||||
* @param {string} path - API path to post to
|
||||
* @param {Object} data - Data to post
|
||||
* @param {Object} options - Additional fetch options
|
||||
* @returns {Promise<any>} - JSON response
|
||||
*/
|
||||
post: async (path, data, options = {}) => {
|
||||
const url = getApiUrl(path);
|
||||
console.log(`[API] Posting to: ${url}`);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
...options,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Create a singleton instance for easier imports
|
||||
export const apiClient = createApiClient();
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Utility functions to access runtime configuration values
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets configuration from runtime values (window.RUNTIME_CONFIG) with fallback to environment variables
|
||||
* This ensures dynamic configuration at runtime instead of build time
|
||||
*/
|
||||
export function useRuntimeConfig() {
|
||||
// For server-side rendering, use environment variables
|
||||
if (typeof window === 'undefined') {
|
||||
return {
|
||||
apiUrl: process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL,
|
||||
backendUrl: process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL,
|
||||
domain: process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN,
|
||||
defaultOrg: process.env.NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG || 'default',
|
||||
multiOrg: process.env.NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG === 'true',
|
||||
topDomain: process.env.NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN
|
||||
};
|
||||
}
|
||||
|
||||
// For client-side, prioritize runtime config over baked-in environment variables
|
||||
const config = window.RUNTIME_CONFIG || {};
|
||||
return {
|
||||
apiUrl: config.LEARNHOUSE_API_URL || process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL,
|
||||
backendUrl: config.LEARNHOUSE_BACKEND_URL || process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL,
|
||||
domain: config.LEARNHOUSE_DOMAIN || process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN,
|
||||
defaultOrg: config.LEARNHOUSE_DEFAULT_ORG || process.env.NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG || 'default',
|
||||
multiOrg: config.LEARNHOUSE_MULTI_ORG === 'true' || process.env.NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG === 'true',
|
||||
topDomain: config.LEARNHOUSE_TOP_DOMAIN || process.env.NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the API URL with the correct domain
|
||||
* @param {string} path - The API path
|
||||
* @returns {string} - The complete API URL
|
||||
*/
|
||||
export function getApiUrl(path) {
|
||||
const config = useRuntimeConfig();
|
||||
return `${config.apiUrl || `https://${config.domain}/api/v1/`}${path}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the backend URL with the correct domain
|
||||
* @param {string} path - The backend path
|
||||
* @returns {string} - The complete backend URL
|
||||
*/
|
||||
export function getBackendUrl(path) {
|
||||
const config = useRuntimeConfig();
|
||||
return `${config.backendUrl || `https://${config.domain}/`}${path}`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue