forked from jsnbuchanan/crowd-funder-for-time-pwa
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.
108 lines
3.4 KiB
TypeScript
108 lines
3.4 KiB
TypeScript
import { defineConfig, UserConfig, Plugin } from "vite";
|
|
import vue from "@vitejs/plugin-vue";
|
|
import dotenv from "dotenv";
|
|
import { loadAppConfig } from "./vite.config.utils.mts";
|
|
import path from "path";
|
|
import { fileURLToPath } from 'url';
|
|
|
|
// Load environment variables
|
|
dotenv.config();
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
export async function createBuildConfig(mode: string): Promise<UserConfig> {
|
|
const appConfig = await loadAppConfig();
|
|
const isCapacitor = mode === "capacitor";
|
|
const isElectron = mode === "electron";
|
|
const isNative = isCapacitor || isElectron;
|
|
|
|
// Set platform and disable PWA for native platforms
|
|
process.env.VITE_PLATFORM = mode;
|
|
process.env.VITE_PWA_ENABLED = isNative ? 'false' : 'true';
|
|
process.env.VITE_DISABLE_PWA = isNative ? 'true' : 'false';
|
|
|
|
if (isNative) {
|
|
process.env.VITE_PWA_ENABLED = 'false';
|
|
}
|
|
|
|
return {
|
|
base: "/",
|
|
plugins: [vue()],
|
|
server: {
|
|
port: parseInt(process.env.VITE_PORT || "8080"),
|
|
fs: { strict: false },
|
|
// CORS headers disabled to allow images from any domain
|
|
// This means SharedArrayBuffer is unavailable, but absurd-sql
|
|
// will automatically fall back to IndexedDB mode which still works
|
|
},
|
|
build: {
|
|
outDir: "dist",
|
|
assetsDir: 'assets',
|
|
chunkSizeWarningLimit: 1000,
|
|
rollupOptions: {
|
|
external: isNative
|
|
? ['@capacitor/app']
|
|
: [],
|
|
output: {
|
|
format: 'esm',
|
|
generatedCode: {
|
|
preset: 'es2015'
|
|
},
|
|
manualChunks: undefined
|
|
}
|
|
}
|
|
},
|
|
worker: {
|
|
format: 'es',
|
|
plugins: () => []
|
|
},
|
|
define: {
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
|
'process.env.VITE_PWA_ENABLED': JSON.stringify(!isNative),
|
|
'process.env.VITE_DISABLE_PWA': JSON.stringify(isNative),
|
|
__dirname: JSON.stringify(process.cwd()),
|
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
|
__IS_ELECTRON__: JSON.stringify(isElectron),
|
|
__USE_QR_READER__: JSON.stringify(!isCapacitor),
|
|
'process.platform': JSON.stringify('browser'),
|
|
'process.version': JSON.stringify('v16.0.0'),
|
|
'process.env.NODE_DEBUG': JSON.stringify(false),
|
|
'global.process': JSON.stringify({
|
|
platform: 'browser',
|
|
version: 'v16.0.0',
|
|
env: { NODE_DEBUG: false }
|
|
})
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, 'src'),
|
|
'@nostr/tools': path.resolve(__dirname, 'node_modules/@nostr/tools'),
|
|
'@nostr/tools/nip06': path.resolve(__dirname, 'node_modules/@nostr/tools/nip06'),
|
|
...appConfig.aliasConfig,
|
|
'path': path.resolve(__dirname, './src/utils/node-modules/path.js'),
|
|
'fs': path.resolve(__dirname, './src/utils/node-modules/fs.js'),
|
|
'crypto': path.resolve(__dirname, './src/utils/node-modules/crypto.js'),
|
|
'dexie-export-import': path.resolve(__dirname, 'node_modules/dexie-export-import')
|
|
}
|
|
},
|
|
optimizeDeps: {
|
|
include: [
|
|
'@nostr/tools',
|
|
'@nostr/tools/nip06',
|
|
],
|
|
exclude: isNative ? [
|
|
'register-service-worker',
|
|
'workbox-window',
|
|
'web-push',
|
|
'serviceworker-webpack-plugin',
|
|
'vite-plugin-pwa',
|
|
'@vite-pwa/vue'
|
|
] : []
|
|
}
|
|
};
|
|
}
|
|
|
|
export default defineConfig(async () => createBuildConfig('web'));
|