@@ -285,38 +285,33 @@ <h2>{{title}}</h2>
285285 submitButton . value = 'Sending...' ;
286286
287287 try {
288- // Get the base URL for config loading
288+ // For local development, load from config.json
289289 const getConfigPath = ( ) => {
290- const origin = window . location . origin ;
291- const pathname = window . location . pathname ;
292-
293- // If we're at the root or index.html
294- if ( pathname === '/' || pathname . endsWith ( 'index.html' ) ) {
290+ if ( window . location . hostname === 'localhost' ||
291+ window . location . hostname === '127.0.0.1' ||
292+ window . location . hostname === '' ) {
295293 return '/config.json' ;
296294 }
297-
298- // Remove any trailing slashes and index.html
299- const cleanPath = pathname . replace ( / \/ + $ / , '' ) . replace ( / \/ i n d e x \. h t m l $ / , '' ) ;
300-
301- // For subdirectory deployments (including GitHub Pages)
302- return `${ cleanPath } /config.json` ;
295+ return null ;
303296 } ;
304297
305- const configPath = getConfigPath ( ) ;
306- console . log ( 'Loading config from:' , configPath ) ;
307- console . log ( 'Full URL:' , window . location . origin + configPath ) ;
298+ // This line will be replaced during build for production
299+ let webhookUrl = null ;
308300
309- // Load webhook URL from config file
310- const configResponse = await fetch ( configPath ) ;
311- if ( ! configResponse . ok ) {
312- console . error ( 'Config fetch failed:' , configResponse . status , configResponse . statusText ) ;
313- throw new Error ( `Failed to load configuration. Please try again later.` ) ;
301+ // Try to load from config for local development
302+ if ( ! webhookUrl ) {
303+ const configPath = getConfigPath ( ) ;
304+ if ( configPath ) {
305+ console . log ( 'Loading config from:' , configPath ) ;
306+ const configResponse = await fetch ( configPath ) ;
307+ if ( ! configResponse . ok ) {
308+ throw new Error ( 'Failed to load configuration' ) ;
309+ }
310+ const config = await configResponse . json ( ) ;
311+ webhookUrl = config . webhookUrl ;
312+ }
314313 }
315314
316- const config = await configResponse . json ( ) ;
317- console . log ( 'Config loaded:' , { hasWebhook : ! ! config . webhookUrl } ) ;
318-
319- const webhookUrl = config . webhookUrl ;
320315 if ( ! webhookUrl ) {
321316 throw new Error ( 'Contact form is not properly configured. Please try again later.' ) ;
322317 }
0 commit comments