Skip to content

Commit 47df1a8

Browse files
remove intermediary step for secret config
1 parent 1b6641c commit 47df1a8

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

.github/workflows/deploy.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ jobs:
3737
exit 1
3838
fi
3939
40-
- name: Create config file
40+
- name: Inject webhook URL
4141
env:
4242
WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
4343
run: |
44-
echo "Creating config.json in repository root..."
45-
echo "{\"webhookUrl\":\"$WEBHOOK_URL\"}" > config.json
46-
echo "Config file created. Verifying contents (webhook URL hidden):"
47-
cat config.json | sed 's/https:\/\/[^"]*/"[WEBHOOK_URL_HIDDEN]"/'
48-
echo "File permissions and size:"
49-
ls -l config.json
50-
echo "Directory contents after config creation:"
51-
ls -la
44+
echo "Injecting webhook URL into index.html..."
45+
# Create a temporary file with the replacement
46+
sed "s|const getConfigPath = .*|const webhookUrl = '$WEBHOOK_URL'; // Injected during build|" index.html > index.html.tmp
47+
# Replace the original file
48+
mv index.html.tmp index.html
49+
echo "Webhook URL injected successfully"
5250
5351
- name: Setup Pages
5452
uses: actions/configure-pages@v4

index.html

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/\/index\.html$/, '');
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

Comments
 (0)