Skip to content

Modern Docker Management, Designed for Everyone

fix: cleanup hooks and layout logic and disable SSR so local development works

Kyle Mendelle3750e5359e5
diff --git a/frontend/.prettierrc b/frontend/.prettierrc
index 4d9f8c8b6..3f7802c37 100644
--- a/frontend/.prettierrc
+++ b/frontend/.prettierrc
@@ -2,7 +2,7 @@
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
- "printWidth": 300,
+ "printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [
{
diff --git a/frontend/package.json b/frontend/package.json
index bc4c6bf6a..44bf661bd 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -1,7 +1,7 @@
{
"name": "arcane",
"private": true,
- "version": "0.15.0",
+ "version": "0.15.1",
"type": "module",
"scripts": {
"dev": "vite dev --port 3000",
diff --git a/frontend/src/hooks.client.ts b/frontend/src/hooks.client.ts
index 4adef9acd..a37326402 100644
--- a/frontend/src/hooks.client.ts
+++ b/frontend/src/hooks.client.ts
@@ -1,107 +1,13 @@
import { sequence } from '@sveltejs/kit/hooks';
import type { Handle } from '@sveltejs/kit';
-import { redirect } from '@sveltejs/kit';
-import { building, dev } from '$app/environment';
-import { settingsAPI } from '$lib/services/api';
-import settingsStore from '$lib/stores/config-store';
-import { authService } from '$lib/services/api/auth-api-service';
+import { building } from '$app/environment';
-const isTestEnvironment = process.env.APP_ENV === 'TEST';
-
-const settingsHandler: Handle = async ({ event, resolve }) => {
- if (building) {
- return resolve(event);
- }
-
- const { url } = event;
- const path = url.pathname;
-
- const isAuthPath = path.startsWith('/auth/') || path.startsWith('/api/');
-
- if (!isAuthPath) {
- try {
- const settings = await settingsAPI.getSettings();
- settingsStore.set(settings);
- } catch (error) {
- console.error('Failed to initialize settings store:', error);
- }
- }
-
- return resolve(event);
-};
-
-const authHandler: Handle = async ({ event, resolve }) => {
- if (building) {
- return resolve(event);
- }
-
- const { url } = event;
- const path = url.pathname;
-
- const publicPaths = ['/auth/login', '/auth/logout', '/img', '/auth/oidc/login', '/auth/oidc/callback', '/api/health', '/api/version', '/favicon.ico', '/_app'];
-
- const isPublicPath = publicPaths.some((p) => path.startsWith(p));
-
- if (path.startsWith('/api/')) {
- return await resolve(event);
- }
-
- if (dev && !isTestEnvironment) {
- try {
- const isValidSession = await authService.validateSession();
-
- if (!isValidSession) {
- throw redirect(302, `/auth/login?redirect=${encodeURIComponent(path)}`);
- }
-
- const isOnboardingPath = path.startsWith('/onboarding');
-
- if (!isOnboardingPath) {
- try {
- const backendUrl = process.env.BACKEND_URL || 'http://localhost:8080';
- const settingsResponse = await fetch(`${backendUrl}/api/settings`, {
- credentials: 'include',
- headers: {
- Cookie: event.request.headers.get('Cookie') || ''
- }
- });
-
- if (settingsResponse.ok) {
- const settingsData = await settingsResponse.json();
- const settings = settingsData.settings || settingsData.data || settingsData;
-
- if (!settings?.onboarding?.completed) {
- throw redirect(302, '/onboarding/welcome');
- }
- }
- } catch (error) {
- console.error('Error checking onboarding status:', error);
- // Don't redirect on error - let the user continue
- }
- }
- } catch (error) {
- // Re-throw SvelteKit redirect errors
- if (error instanceof redirect) {
- throw error;
- }
-
- console.error('Session validation error:', error);
- throw redirect(302, `/auth/login?redirect=${encodeURIComponent(path)}`);
- }
- }
-
- return await resolve(event);
-};
-
-// Simple initialization handler
const initHandler: Handle = async ({ event, resolve }) => {
- // Skip initialization during build
if (building) {
return resolve(event);
}
- // No frontend initialization needed - everything is handled by the backend
return resolve(event);
};
-export const handle = sequence(settingsHandler, initHandler, authHandler);
+export const handle = sequence(initHandler);
diff --git a/frontend/src/lib/services/api/settings-api-service.ts b/frontend/src/lib/services/api/settings-api-service.ts
index b279c75ac..e1e8010a6 100644
--- a/frontend/src/lib/services/api/settings-api-service.ts
+++ b/frontend/src/lib/services/api/settings-api-service.ts
@@ -13,6 +13,17 @@ export default class SettingsAPIService extends BaseAPIService {
}
}
+ async getPublicSettings(): Promise<Settings> {
+ try {
+ const response = await this.api.get('/settings/public');
+ const data = response.data?.settings || response.data?.data || response.data;
+ return data;
+ } catch (error) {
+ console.error('Error fetching settings:', error);
+ throw error;
+ }
+ }
+
async updateSettings(settings: Partial<Settings>): Promise<Settings> {
try {
const response = await this.api.put('/settings', settings);
diff --git a/frontend/src/lib/services/app-config-service.ts b/frontend/src/lib/services/app-config-service.ts
deleted file mode 100644
index 18caf2960..000000000
--- a/frontend/src/lib/services/app-config-service.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import { version as currentVersion } from '$app/environment';
-import type { AppVersionInformation } from '$lib/types/application-configuration';
-
-export default class AppConfigService {
- /**
- * Fetches version information from GitHub or a configured API
- */
- async getVersionInformation(): Promise<AppVersionInformation> {
- try {
- const apiUrl = 'https://api.github.com/repos/ofkm/arcane/releases/latest';
-
- const response = await fetch(apiUrl);
- if (!response.ok) {
- throw new Error(`Failed to fetch version info: ${response.status}`);
- }
-
- const data = await response.json();
-
- // GitHub release tag usually starts with 'v' (e.g., 'v1.0.0')
- // Remove the 'v' prefix if present to compare versions properly
- const newestVersion = data.tag_name.replace(/^v/, '');
- const currentVersionClean = currentVersion.replace(/^v/, '');
-
- // Simple version comparison (you might want a more robust solution)
- const updateAvailable = this.isNewerVersion(newestVersion, currentVersionClean);
-
- return {
- currentVersion: currentVersion,
- newestVersion: newestVersion,
- updateAvailable: updateAvailable,
- releaseUrl: data.html_url,
- releaseNotes: data.body
- };
- } catch (error) {
- console.error('Error fetching version information:', error);
- return { currentVersion };
- }
- }
-
- /**
- * Compare versions to determine if an update is available
- * Simple version comparison, assumes semantic versioning (x.y.z)
- */
- private isNewerVersion(latest: string, current: string): boolean {
- if (!latest || !current) return false;
-
- const latestParts = latest.split('.').map(Number);
- const currentParts = current.split('.').map(Number);
-
- for (let i = 0; i < 3; i++) {
- if ((latestParts[i] || 0) > (currentParts[i] || 0)) return true;
- if ((latestParts[i] || 0) < (currentParts[i] || 0)) return false;
- }
-
- return false;
- }
-}
diff --git a/frontend/src/lib/services/app-version-service.ts b/frontend/src/lib/services/app-version-service.ts
new file mode 100644
index 000000000..b1b11f791
--- /dev/null
+++ b/frontend/src/lib/services/app-version-service.ts
@@ -0,0 +1,72 @@
+import { version as currentVersion } from '$app/environment';
+import type { AppVersionInformation } from '$lib/types/application-configuration';
+
+export class AppVersionService {
+ private cachedVersionInfo: AppVersionInformation | null = null;
+ private lastFetchTime: number = 0;
+ private readonly cacheExpiry = 1000 * 60 * 60 * 3; // 3 hours
+
+ getCurrentVersion(): string {
+ return currentVersion;
+ }
+
+ async getNewestVersion(): Promise<string> {
+ try {
+ const response = await fetch('https://api.github.com/repos/ofkm/arcane/releases/latest');
+ if (!response.ok) throw new Error(`Failed to fetch: ${response.status}`);
+
+ const data = await response.json();
+ return data.tag_name.replace(/^v/, '');
+ } catch (error) {
+ console.error('Error fetching newest version:', error);
+ return this.getCurrentVersion();
+ }
+ }
+
+ async isUpToDate(): Promise<boolean> {
+ const newest = await this.getNewestVersion();
+ const current = this.getCurrentVersion().replace(/^v/, '');
+ return !this.isNewerVersion(newest, current);
+ }
+
+ async getVersionInformation(): Promise<AppVersionInformation> {
+ const cacheExpired = Date.now() - this.lastFetchTime > this.cacheExpiry;
+
+ if (!this.cachedVersionInfo || cacheExpired) {
+ try {
+ const [newestVersion, isUpToDate] = await Promise.all([
+ this.getNewestVersion(),
+ this.isUpToDate()
+ ]);
+
+ this.cachedVersionInfo = {
+ currentVersion: this.getCurrentVersion(),
+ newestVersion,
+ updateAvailable: !isUpToDate
+ };
+ this.lastFetchTime = Date.now();
+ } catch (error) {
+ console.error('Error fetching version information:', error);
+ return { currentVersion: this.getCurrentVersion() };
+ }
+ }
+
+ return this.cachedVersionInfo;
+ }
+
+ private isNewerVersion(latest: string, current: string): boolean {
+ if (!latest || !current) return false;
+
+ const latestParts = latest.split('.').map(Number);
+ const currentParts = current.split('.').map(Number);
+
+ for (let i = 0; i < 3; i++) {
+ if ((latestParts[i] || 0) > (currentParts[i] || 0)) return true;
+ if ((latestParts[i] || 0) < (currentParts[i] || 0)) return false;
+ }
+
+ return false;
+ }
+}
+
+export const versionService = new AppVersionService();
diff --git a/frontend/src/lib/utils/redirect.util.ts b/frontend/src/lib/utils/redirect.util.ts
new file mode 100644
index 000000000..29705fa40
--- /dev/null
+++ b/frontend/src/lib/utils/redirect.util.ts
@@ -0,0 +1,33 @@
+import type { User } from '$lib/types/user.type';
+import type { Settings } from '$lib/types/settings.type';
+
+// Returns the path to redirect to based on the current path and user authentication status
+// If no redirect is needed, it returns null
+export function getAuthRedirectPath(path: string, user: User | null, settings: Settings | null) {
+ const isSignedIn = !!user;
+
+ const isUnauthenticatedOnlyPath =
+ path == '/auth/login' ||
+ path.startsWith('/auth/login/') ||
+ path == '/auth/oidc/login' ||
+ path.startsWith('/auth/oidc/login') ||
+ path == '/auth/oidc/callback' ||
+ path.startsWith('/auth/oidc/callback') ||
+ path == '/img' ||
+ path.startsWith('/img') ||
+ path == '/favicon.ico';
+ const isPublicPath = ['/authorize', '/device', '/health', '/healthz'].includes(path);
+ const isOnboardingPath = path == '/onboarding' || path.startsWith('/onboarding');
+
+ if (!isOnboardingPath && settings && settings.onboarding && !settings.onboarding.completed) {
+ return '/onboarding/welcome';
+ }
+
+ if (!isUnauthenticatedOnlyPath && !isPublicPath && !isSignedIn) {
+ return '/auth/login';
+ }
+
+ if (isUnauthenticatedOnlyPath && isSignedIn) {
+ return '/';
+ }
+}
diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte
index 959d2a71a..54fc0d0da 100644
--- a/frontend/src/routes/+layout.svelte
+++ b/frontend/src/routes/+layout.svelte
@@ -6,54 +6,36 @@
import ConfirmDialog from '$lib/components/confirm-dialog/confirm-dialog.svelte';
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
import AppSidebar from '$lib/components/sidebar/sidebar.svelte';
- import { onMount } from 'svelte';
import { goto } from '$app/navigation';
- import { initializeClientStores } from '$lib/stores/client-init';
import userStore from '$lib/stores/user-store';
+ import settingsStore from '$lib/stores/config-store';
+ import { getAuthRedirectPath } from '$lib/utils/redirect.util';
let { children, data } = $props();
- const versionInformation = data.versionInformation;
- const user = $derived(data.user);
- const isNavigating = $derived(navigating.type !== null);
- const isAuthenticated = $derived(!!user);
- const isOnboardingPage = $derived(page.url.pathname.startsWith('/onboarding'));
- const isLoginPage = $derived(page.url.pathname === '/login' || page.url.pathname.startsWith('/auth/login') || page.url.pathname === '/auth' || page.url.pathname.includes('/login'));
- const showSidebar = $derived(isAuthenticated && !isOnboardingPage && !isLoginPage);
-
- $effect(() => {
- const path = page.url.pathname;
+ const { versionInformation, user, settings } = data;
- const publicPaths = ['/auth/login', '/auth/logout', '/auth/oidc/login', '/auth/oidc/callback', '/img', '/favicon.ico'];
-
- const isPublicPath = publicPaths.some((p) => path.startsWith(p));
+ const redirectPath = getAuthRedirectPath(page.url.pathname, user, settings);
+ if (redirectPath) {
+ goto(redirectPath);
+ }
+ const isNavigating = $derived(navigating.type !== null);
- if (!isPublicPath && !data.isAuthenticated) {
- fetch('/api/auth/me', {
- credentials: 'include'
- })
- .then((response) => {
- if (!response.ok) {
- goto(`/auth/login?redirect=${encodeURIComponent(path)}`);
- }
- })
- .catch(() => {
- goto(`/auth/login?redirect=${encodeURIComponent(path)}`);
- });
- }
- });
+ const isOnboardingPage = $derived(page.url.pathname.startsWith('/onboarding'));
+ const isLoginPage = $derived(
+ page.url.pathname === '/login' ||
+ page.url.pathname.startsWith('/auth/login') ||
+ page.url.pathname === '/auth' ||
+ page.url.pathname.includes('/login')
+ );
- $effect(() => {
- if (user) {
- userStore.setUser(user);
- } else {
- userStore.clearUser();
- }
- });
+ if (user) {
+ userStore.setUser(user);
+ }
- onMount(async () => {
- await initializeClientStores();
- });
+ if (settings) {
+ settingsStore.set(settings);
+ }
</script>
<svelte:head><title>Arcane</title></svelte:head>
@@ -70,7 +52,7 @@
{/if}
<div class="bg-background flex min-h-screen">
- {#if showSidebar}
+ {#if !!$userStore && !isOnboardingPage && !isLoginPage}
<Sidebar.Provider>
<AppSidebar {versionInformation} {user} />
<main class="flex-1">
diff --git a/frontend/src/routes/+layout.ts b/frontend/src/routes/+layout.ts
index bc20fb7c6..decc432a5 100644
--- a/frontend/src/routes/+layout.ts
+++ b/frontend/src/routes/+layout.ts
@@ -1,116 +1,43 @@
-import { browser } from '$app/environment';
import { env } from '$env/dynamic/public';
-import { redirect } from '@sveltejs/kit';
import type { AppVersionInformation } from '$lib/types/application-configuration';
import { settingsAPI, userAPI, environmentManagementAPI } from '$lib/services/api';
import { environmentStore } from '$lib/stores/environment.store';
+import { versionService } from '$lib/services/app-version-service';
+import { tryCatch } from '$lib/utils/try-catch';
-let versionInformation: AppVersionInformation;
-let versionInformationLastUpdated: number;
-
-export const load = async ({ fetch, url }) => {
- let csrf: string;
- try {
- csrf = crypto.randomUUID();
- } catch {
- csrf = Math.random().toString(36).substring(2) + Date.now().toString(36);
- }
+export const ssr = false;
+export const load = async ({}) => {
const updateCheckDisabled = env.PUBLIC_UPDATE_CHECK_DISABLED === 'true';
- let isAuthenticated = false;
- let user = null;
- let settings: any = null;
-
- const path = url.pathname;
- const publicPaths = ['/auth/login', '/auth/logout', '/auth/oidc/login', '/auth/oidc/callback', '/img', '/favicon.ico'];
- const isPublicPath = publicPaths.some((p) => path.startsWith(p));
-
- try {
- settings = await settingsAPI.getSettings();
- } catch (e: any) {
- if (isPublicPath) {
- try {
- const publicSettingsResponse = await fetch('/api/settings/public');
- if (publicSettingsResponse.ok) {
- const publicData = await publicSettingsResponse.json();
- if (publicData.success) settings = publicData.data;
- }
- } catch (publicError) {
- console.warn('Could not fetch public settings:', publicError);
- }
- }
- }
-
- try {
- user = await userAPI.getCurrentUser();
- if (user) {
- isAuthenticated = true;
- }
- } catch (e: any) {
- user = null;
- isAuthenticated = false;
+ let arcaneSettings = await tryCatch(settingsAPI.getSettings());
+ if (arcaneSettings.error) {
+ console.error('Failed to load all setting settings');
+ arcaneSettings = await tryCatch(settingsAPI.getPublicSettings());
}
- if (!isPublicPath && !isAuthenticated) {
- throw redirect(302, `/auth/login?redirect=${encodeURIComponent(path)}`);
+ const arcaneUser = await tryCatch(userAPI.getCurrentUser());
+ if (arcaneUser.error) {
+ console.error('Failed to load user information');
}
- if (isAuthenticated && !isPublicPath) {
- if (!environmentStore.isInitialized()) {
- try {
- const environments = await environmentManagementAPI.list();
- let hasLocalDocker = false;
- if (browser) {
- // Check for local Docker only in browser context
- try {
- const localDockerCheckUrl = '/api/environments/0/containers?limit=1';
- const dockerResponse = await fetch(localDockerCheckUrl);
- hasLocalDocker = dockerResponse.ok;
- } catch (e) {
- console.warn('Failed to check for local Docker:', e);
- hasLocalDocker = false;
- }
- }
- await environmentStore.initialize(environments, hasLocalDocker);
- } catch (error) {
- console.error('Failed to load and initialize environments in layout load:', error);
- await environmentStore.initialize([], false); // Initialize with empty state
- }
- }
+ if (!environmentStore.isInitialized()) {
+ const environments = await tryCatch(environmentManagementAPI.list());
- const isOnboardingPath = path.startsWith('/onboarding');
- if (!isOnboardingPath && settings && settings.onboarding && !settings.onboarding.completed) {
- throw redirect(302, '/onboarding/welcome');
- }
+ await environmentStore.initialize(environments.data || [], true);
}
+ let versionInformation: AppVersionInformation;
if (updateCheckDisabled) {
- versionInformation = { currentVersion: '0.15.0' } as AppVersionInformation;
+ versionInformation = { currentVersion: versionService.getCurrentVersion() };
} else {
- const cacheExpired = versionInformationLastUpdated && Date.now() - versionInformationLastUpdated > 1000 * 60 * 60 * 3;
- if (!versionInformation || cacheExpired) {
- try {
- const versionResponse = await fetch('/_app/version.json');
- if (versionResponse.ok) {
- const versionData = await versionResponse.json();
- versionInformation = { currentVersion: versionData.version } as AppVersionInformation;
- versionInformationLastUpdated = Date.now();
- } else {
- throw new Error('Version endpoint not available');
- }
- } catch (error) {
- console.error('Error fetching version information:', error);
- versionInformation = { currentVersion: 'Unknown' } as AppVersionInformation;
- }
- }
+ versionInformation = await versionService.getVersionInformation();
}
return {
- csrf,
- user,
- isAuthenticated,
- settings,
+ user: arcaneUser.data,
+ isAuthenticated: !!arcaneUser.data,
+ settings: arcaneSettings.data,
versionInformation,
updateCheckDisabled
};
diff --git a/frontend/src/routes/settings/general/+page.svelte b/frontend/src/routes/settings/general/+page.svelte
index ff2bea09a..14d222a89 100644
--- a/frontend/src/routes/settings/general/+page.svelte
+++ b/frontend/src/routes/settings/general/+page.svelte
@@ -2,7 +2,7 @@
import * as Card from '$lib/components/ui/card/index.js';
import FormInput from '$lib/components/form/form-input.svelte';
import { Button } from '$lib/components/ui/button/index.js';
- import { Cog, Save, RefreshCw, Folder, Globe, Calendar } from '@lucide/svelte';
+ import { Save, RefreshCw, Folder, Globe, Calendar } from '@lucide/svelte';
import type { FormInput as FormInputType } from '$lib/utils/form.utils';
import { toast } from 'svelte-sonner';
import { invalidateAll } from '$app/navigation';
@@ -68,10 +68,16 @@
<div class="flex flex-col justify-between gap-4 sm:flex-row sm:items-center">
<div>
<h1 class="text-3xl font-bold tracking-tight">General Settings</h1>
- <p class="text-muted-foreground mt-1 text-sm">Core configuration for how Arcane operates and manages your containers</p>
+ <p class="text-muted-foreground mt-1 text-sm">
+ Core configuration for how Arcane operates and manages your containers
+ </p>
</div>
- <Button onclick={() => handleGeneralSettingUpdates()} disabled={isLoading.saving} class="h-10 min-w-[120px]">
+ <Button
+ onclick={() => handleGeneralSettingUpdates()}
+ disabled={isLoading.saving}
+ class="h-10 min-w-[120px]"
+ >
{#if isLoading.saving}
<RefreshCw class="size-4 animate-spin" />
Saving...
@@ -98,7 +104,12 @@
</div>
</Card.Header>
<Card.Content>
- <FormInput label="Stacks Directory" placeholder="data/stacks" bind:input={stacksDirectoryInput} helpText="Directory where Docker Compose stack files are stored" />
+ <FormInput
+ label="Stacks Directory"
+ placeholder="data/stacks"
+ bind:input={stacksDirectoryInput}
+ helpText="Directory where Docker Compose stack files are stored"
+ />
</Card.Content>
</Card.Root>
@@ -116,7 +127,12 @@
</div>
</Card.Header>
<Card.Content>
- <FormInput label="Base Server URL" placeholder="localhost" bind:input={baseServerUrlInput} helpText="Base URL for accessing Arcane (used for webhooks and notifications)" />
+ <FormInput
+ label="Base Server URL"
+ placeholder="localhost"
+ bind:input={baseServerUrlInput}
+ helpText="Base URL for accessing Arcane (used for webhooks and notifications)"
+ />
</Card.Content>
</Card.Root>
@@ -134,7 +150,13 @@
</div>
</Card.Header>
<Card.Content>
- <FormInput type="number" label="Image Maturity Threshold (Days)" placeholder="30" bind:input={maturityThresholdInput} helpText="Number of days to wait before considering an image update stable" />
+ <FormInput
+ type="number"
+ label="Image Maturity Threshold (Days)"
+ placeholder="30"
+ bind:input={maturityThresholdInput}
+ helpText="Number of days to wait before considering an image update stable"
+ />
</Card.Content>
</Card.Root>
</div>
diff --git a/frontend/svelte.config.js b/frontend/svelte.config.js
index fd5d292a0..c7b0fb29e 100644
--- a/frontend/svelte.config.js
+++ b/frontend/svelte.config.js
@@ -9,12 +9,6 @@ const config = {
pages: process.env.BUILD_PATH ?? '../backend/frontend/dist',
fallback: 'index.html'
}),
- paths: {
- base: process.env.NODE_ENV === 'production' ? '' : ''
- },
- csrf: {
- checkOrigin: process.env.NODE_ENV === 'production'
- },
version: {
name: packageJson.version
}
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index 624a954b3..9a1cf171a 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -5,10 +5,10 @@ import { defineConfig } from 'vite';
export default defineConfig({
plugins: [tailwindcss(), sveltekit()],
server: {
+ host: process.env.HOST,
proxy: {
'/api': {
- target: 'http://localhost:8080',
- changeOrigin: true
+ target: process.env.DEV_BACKEND_URL || 'http://localhost:8080'
}
}
}