fix: enhance Redis connection handling and improve error logging in API startup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { getOrgBySiteName } from '$features/org/api/org.server';
|
||||
import { getApiKeyHeaders } from '$lib/utils/services/api/server';
|
||||
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { getApiKeyHeaders } from '$lib/utils/services/api/server';
|
||||
import { getOrgBySiteName } from '$features/org/api/org.server';
|
||||
import { getSubdomain } from '$features/app/layout-setup';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
@@ -12,7 +13,8 @@ export const load = async ({ params, url, cookies }) => {
|
||||
const isOrgSite = subdomain && !APP_SUBDOMAINS.includes(subdomain);
|
||||
|
||||
// If this is LMS but user is on org site, redirect to LMS
|
||||
if (isOrgSite) {
|
||||
if (isOrgSite && PUBLIC_IS_SELFHOSTED !== 'true') {
|
||||
console.log('isOrgSite redirecting to lms');
|
||||
redirect(307, `/lms`);
|
||||
}
|
||||
|
||||
@@ -20,11 +22,15 @@ export const load = async ({ params, url, cookies }) => {
|
||||
const cookieKey = `${ORG_ID_COOKIE_PREFIX}${siteName}`;
|
||||
const cachedOrgId = cookies.get(cookieKey);
|
||||
|
||||
console.log('cachedOrgId', cachedOrgId);
|
||||
console.log('cookieKey', cookieKey);
|
||||
|
||||
let orgId: string | undefined = cachedOrgId;
|
||||
|
||||
if (!orgId) {
|
||||
const apiKeyHeaders = getApiKeyHeaders();
|
||||
const org = await getOrgBySiteName(siteName, apiKeyHeaders);
|
||||
console.log('org', org);
|
||||
if (org?.id) {
|
||||
orgId = org.id;
|
||||
|
||||
@@ -37,6 +43,8 @@ export const load = async ({ params, url, cookies }) => {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('returning orgId', orgId);
|
||||
|
||||
return {
|
||||
orgName: siteName,
|
||||
orgId
|
||||
|
||||
@@ -13,6 +13,9 @@ export const load = async ({ params, parent, cookies }) => {
|
||||
stats: null
|
||||
};
|
||||
}
|
||||
console.log('cache', cache);
|
||||
console.log('orgId', orgId);
|
||||
console.log('siteName', siteName);
|
||||
|
||||
if (cache[orgId]) {
|
||||
return {
|
||||
@@ -21,11 +24,15 @@ export const load = async ({ params, parent, cookies }) => {
|
||||
};
|
||||
}
|
||||
|
||||
// Fetch dashboard stats
|
||||
const statsResponse = await classroomio.dash.stats.$get({ query: { siteName } }, getApiHeaders(cookies, orgId));
|
||||
|
||||
const statsData = await statsResponse.json();
|
||||
cache[orgId] = statsData.success ? statsData.data : null;
|
||||
try {
|
||||
console.log('fetching stats', cookies);
|
||||
const statsResponse = await classroomio.dash.stats.$get({ query: { siteName } }, getApiHeaders(cookies, orgId));
|
||||
const statsData = await statsResponse.json();
|
||||
cache[orgId] = statsData.success ? statsData.data : null;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch dashboard stats:', error);
|
||||
cache[orgId] = null;
|
||||
}
|
||||
|
||||
return {
|
||||
orgName: siteName,
|
||||
|
||||
Reference in New Issue
Block a user