forked from jsnbuchanan/crowd-funder-for-time-pwa
Fix CORS restrictions and development server configuration
Remove CORS headers to enable universal image support and fix local API server settings. ## Changes **Remove CORS Headers** - Remove Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers - Enables images from any domain (Facebook, Medium, arbitrary websites) - Database falls back to IndexedDB mode (minimal performance impact) **Fix Local Development Configuration** - Set LOCAL_ENDORSER_API_SERVER to http://127.0.0.1:3000 (was "/api") - Create .env.development with local API server config - Fix ensureCorrectApiServer() method in HomeView.vue - "Use Local" button now sets proper localhost address **Fix Settings Cache Issues** - Add PlatformServiceMixin to AccountViewView.vue - Disable settings caching to prevent stale data - Settings changes now apply immediately without browser refresh ## Impact **Tradeoffs:** - Lost: ~2x SharedArrayBuffer database performance - Gained: Universal image support from any domain - Result: Better user experience, database still fast via IndexedDB **Files Modified:** - Configuration: vite.config.*.mts, index.html, .env.development - Source: constants/app.ts, libs/util.ts, views/*.vue, utils/PlatformServiceMixin.ts ## Rationale For a community platform, universal image support is more critical than marginal database performance gains. Users share images from arbitrary websites, making CORS restrictions incompatible with Time Safari's core mission.
This commit is contained in:
@@ -521,18 +521,12 @@ export const PlatformServiceMixin = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Load settings with optional defaults and caching - $settings()
|
||||
* Ultra-concise with 30s TTL for massive performance gain
|
||||
* Load settings with optional defaults WITHOUT caching - $settings()
|
||||
* Settings are loaded fresh every time for immediate consistency
|
||||
* @param defaults Optional default values
|
||||
* @returns Cached settings object
|
||||
* @returns Fresh settings object from database
|
||||
*/
|
||||
async $settings(defaults: Settings = {}): Promise<Settings> {
|
||||
const cacheKey = `settings_${String(MASTER_SETTINGS_KEY)}`;
|
||||
const cached = this._getCached<Settings>(cacheKey);
|
||||
if (cached) {
|
||||
return { ...cached, ...defaults }; // Merge with any new defaults
|
||||
}
|
||||
|
||||
const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults);
|
||||
|
||||
if (!settings) {
|
||||
@@ -549,14 +543,15 @@ export const PlatformServiceMixin = {
|
||||
settings.apiServer = DEFAULT_ENDORSER_API_SERVER;
|
||||
}
|
||||
|
||||
return this._setCached(cacheKey, settings, CACHE_DEFAULTS.settings);
|
||||
return settings; // Return fresh data without caching
|
||||
},
|
||||
|
||||
/**
|
||||
* Load account-specific settings with caching - $accountSettings()
|
||||
* Load account-specific settings WITHOUT caching - $accountSettings()
|
||||
* Settings are loaded fresh every time for immediate consistency
|
||||
* @param did DID identifier (optional, uses current active DID)
|
||||
* @param defaults Optional default values
|
||||
* @returns Cached merged settings object
|
||||
* @returns Fresh merged settings object from database
|
||||
*/
|
||||
async $accountSettings(
|
||||
did?: string,
|
||||
@@ -564,12 +559,6 @@ export const PlatformServiceMixin = {
|
||||
): Promise<Settings> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const currentDid = did || (this as any).activeDid;
|
||||
const cacheKey = `account_settings_${currentDid || "default"}`;
|
||||
|
||||
const cached = this._getCached<Settings>(cacheKey);
|
||||
if (cached) {
|
||||
return { ...cached, ...defaults }; // Merge with any new defaults
|
||||
}
|
||||
|
||||
let settings;
|
||||
if (!currentDid) {
|
||||
@@ -582,7 +571,7 @@ export const PlatformServiceMixin = {
|
||||
);
|
||||
}
|
||||
|
||||
return this._setCached(cacheKey, settings, CACHE_DEFAULTS.settings);
|
||||
return settings; // Return fresh data without caching
|
||||
},
|
||||
|
||||
// =================================================
|
||||
@@ -590,23 +579,17 @@ export const PlatformServiceMixin = {
|
||||
// =================================================
|
||||
|
||||
/**
|
||||
* Save default settings with cache invalidation - $saveSettings()
|
||||
* Save default settings - $saveSettings()
|
||||
* Ultra-concise shortcut for updateDefaultSettings
|
||||
* @param changes Settings changes to save
|
||||
* @returns Promise<boolean> Success status
|
||||
*/
|
||||
async $saveSettings(changes: Partial<Settings>): Promise<boolean> {
|
||||
const result = await databaseUtil.updateDefaultSettings(changes);
|
||||
|
||||
// Invalidate related caches
|
||||
this._invalidateCache(`settings_${MASTER_SETTINGS_KEY}`);
|
||||
this._invalidateCache(`account_settings_default`);
|
||||
|
||||
return result;
|
||||
return await databaseUtil.updateDefaultSettings(changes);
|
||||
},
|
||||
|
||||
/**
|
||||
* Save user-specific settings with cache invalidation - $saveUserSettings()
|
||||
* Save user-specific settings - $saveUserSettings()
|
||||
* Ultra-concise shortcut for updateDidSpecificSettings
|
||||
* @param did DID identifier
|
||||
* @param changes Settings changes to save
|
||||
@@ -616,13 +599,7 @@ export const PlatformServiceMixin = {
|
||||
did: string,
|
||||
changes: Partial<Settings>,
|
||||
): Promise<boolean> {
|
||||
const result = await databaseUtil.updateDidSpecificSettings(did, changes);
|
||||
|
||||
// Invalidate related caches
|
||||
this._invalidateCache(`account_settings_${did}`);
|
||||
this._invalidateCache(`settings_${MASTER_SETTINGS_KEY}`);
|
||||
|
||||
return result;
|
||||
return await databaseUtil.updateDidSpecificSettings(did, changes);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -645,16 +622,10 @@ export const PlatformServiceMixin = {
|
||||
// =================================================
|
||||
|
||||
/**
|
||||
* Manually refresh settings cache - $refreshSettings()
|
||||
* Forces reload of settings from database
|
||||
* Refresh settings from database - $refreshSettings()
|
||||
* Since settings are no longer cached, this simply returns fresh settings
|
||||
*/
|
||||
async $refreshSettings(): Promise<Settings> {
|
||||
this._invalidateCache(`settings_${MASTER_SETTINGS_KEY}`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const currentDid = (this as any).activeDid;
|
||||
if (currentDid) {
|
||||
this._invalidateCache(`account_settings_${currentDid}`);
|
||||
}
|
||||
return await this.$settings();
|
||||
},
|
||||
|
||||
@@ -754,7 +725,7 @@ declare module "@vue/runtime-core" {
|
||||
): Promise<Settings>;
|
||||
$withTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
||||
|
||||
// Cached specialized shortcuts (massive performance boost)
|
||||
// Specialized shortcuts - contacts cached, settings fresh
|
||||
$contacts(): Promise<Contact[]>;
|
||||
$settings(defaults?: Settings): Promise<Settings>;
|
||||
$accountSettings(did?: string, defaults?: Settings): Promise<Settings>;
|
||||
|
||||
Reference in New Issue
Block a user