Skip to content

Commit 8f51582

Browse files
MrCoderclaude
andcommitted
fix: Use frontend origin for dynamic base URL generation
- Frontend now passes window.location.origin to Cloud Function - Cloud Function uses frontend origin with environment-specific fallbacks - This automatically handles staging.zenuml.com, app.zenuml.com, localhost:3000 - Eliminates hardcoded URLs and makes the system fully environment-agnostic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c2f464f commit 8f51582

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

functions/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,19 @@ exports.create_share = functions.https.onRequest(async (req, res) => {
166166
const contentHash = crypto.createHash('md5').update(itemData.js || '').digest('hex');
167167

168168
// Return in the same format as the old API
169-
// Use correct host for different environments
170-
let baseUrl;
171-
if (process.env.FUNCTIONS_EMULATOR === 'true') {
172-
// Local development - use Vite dev server
173-
baseUrl = 'http://localhost:3000';
174-
} else if (process.env.GCLOUD_PROJECT === 'staging-zenuml-27954') {
175-
// Staging environment
176-
baseUrl = 'https://staging.zenuml.com';
177-
} else {
178-
// Production environment
179-
baseUrl = 'https://app.zenuml.com';
169+
// Use origin from frontend request, with fallback to environment-specific defaults
170+
let baseUrl = req.body.origin;
171+
if (!baseUrl) {
172+
if (process.env.FUNCTIONS_EMULATOR === 'true') {
173+
// Local development fallback
174+
baseUrl = 'http://localhost:3000';
175+
} else if (process.env.GCLOUD_PROJECT === 'staging-zenuml-27954') {
176+
// Staging environment fallback
177+
baseUrl = 'https://staging.zenuml.com';
178+
} else {
179+
// Production environment fallback
180+
baseUrl = 'https://app.zenuml.com';
181+
}
180182
}
181183

182184
res.json({

src/services/syncService.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ async function syncDiagram(currentItem) {
3131
name: title,
3232
content: js,
3333
description: 'Shared diagram from https://app.zenuml.com',
34+
origin: window.location.origin, // Pass the frontend origin
3435
};
3536
console.log('calling /create-share with data:', data);
3637
try {

0 commit comments

Comments
 (0)