From de3ca11f5bf8f301de12e5db4a2b208ed94c5f0d Mon Sep 17 00:00:00 2001 From: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:27:37 -0500 Subject: [PATCH] fix VITE_ worker URL --- src/components/Board.tsx | 7 ++-- vite.config.ts | 72 +++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/components/Board.tsx b/src/components/Board.tsx index 9d2f9ee..c4d22c7 100644 --- a/src/components/Board.tsx +++ b/src/components/Board.tsx @@ -26,8 +26,11 @@ import { components, uiOverrides } from '@/ui-overrides' import { useCameraControls } from '@/hooks/useCameraControls' import { zoomToSelection } from '../ui-overrides' -//const WORKER_URL = `https://jeffemmett-canvas.jeffemmett.workers.dev` -export const WORKER_URL = import.meta.env.VITE_TLDRAW_WORKER_URL || 'https://jeffemmett-canvas.jeffemmett.workers.dev'; +// Default to production URL if env var isn't available +const DEFAULT_WORKER_URL = 'https://jeffemmett-canvas.jeffemmett.workers.dev'; +export const WORKER_URL = typeof import.meta.env.VITE_TLDRAW_WORKER_URL === 'string' + ? import.meta.env.VITE_TLDRAW_WORKER_URL + : DEFAULT_WORKER_URL; const shapeUtils = [ChatBoxShape, VideoChatShape, EmbedShape] const tools = [ChatBoxTool, VideoChatTool, EmbedTool]; // Array of tools diff --git a/vite.config.ts b/vite.config.ts index 3927bd7..7aba30b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,38 +1,48 @@ import { markdownPlugin } from './build/markdownPlugin'; -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' import wasm from "vite-plugin-wasm"; import topLevelAwait from "vite-plugin-top-level-await"; import { viteStaticCopy } from 'vite-plugin-static-copy'; -export default defineConfig({ - envPrefix: ['VITE_'], - plugins: [ - react(), - wasm(), - topLevelAwait(), - markdownPlugin, - viteStaticCopy({ - targets: [ - { - src: 'src/posts/', - dest: '.' - } - ] - }) - ], - server: { - host: '0.0.0.0', - port: 5173, - }, - build: { - sourcemap: true, - }, - base: '/', - publicDir: 'src/public', - resolve: { - alias: { - '@': '/src', +export default defineConfig(({ mode }) => { + // Load env file based on `mode` in the current working directory. + const env = loadEnv(mode, process.cwd(), ''); + + return { + envPrefix: ['VITE_'], + plugins: [ + react(), + wasm(), + topLevelAwait(), + markdownPlugin, + viteStaticCopy({ + targets: [ + { + src: 'src/posts/', + dest: '.' + } + ] + }) + ], + server: { + host: '0.0.0.0', + port: 5173, }, - }, -}) + build: { + sourcemap: true, + }, + base: '/', + publicDir: 'src/public', + resolve: { + alias: { + '@': '/src', + }, + }, + define: { + 'import.meta.env.VITE_TLDRAW_WORKER_URL': JSON.stringify( + env.VITE_TLDRAW_WORKER_URL || 'https://jeffemmett-canvas.jeffemmett.workers.dev' + ) + } + }; +});