From 2c8e86a605f7dba42001dfbbf1ad431bb1b3a75c Mon Sep 17 00:00:00 2001 From: Matthew Reichhoff Date: Sat, 9 May 2026 17:15:15 -0400 Subject: [PATCH 1/2] Ensure firebase functions run under main domain The URL should probably be configurable, but whatever. --- firebase.json | 44 ++++++++++++++++++++++++++++++++- public/js/modules/data-layer.js | 12 ++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/firebase.json b/firebase.json index a4accd3f..ebda3934 100644 --- a/firebase.json +++ b/firebase.json @@ -10,6 +10,48 @@ "**/node_modules/**" ], "rewrites": [ + { + "source": "/explainText", + "function": { + "functionId": "explainText", + "region": "us-central1" + } + }, + { + "source": "/explainEnglishText", + "function": { + "functionId": "explainEnglishText", + "region": "us-central1" + } + }, + { + "source": "/analyzeImage", + "function": { + "functionId": "analyzeImage", + "region": "us-central1" + } + }, + { + "source": "/generateChineseSentences", + "function": { + "functionId": "generateChineseSentences", + "region": "us-central1" + } + }, + { + "source": "/analyzeCollocation", + "function": { + "functionId": "analyzeCollocation", + "region": "us-central1" + } + }, + { + "source": "/explainWordInContext", + "function": { + "functionId": "explainWordInContext", + "region": "us-central1" + } + }, { "source": "/components/**", "destination": "/components/index.html" @@ -51,4 +93,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/public/js/modules/data-layer.js b/public/js/modules/data-layer.js index e3d12aca..770e75ff 100644 --- a/public/js/modules/data-layer.js +++ b/public/js/modules/data-layer.js @@ -725,7 +725,7 @@ async function explainChineseSentence(text) { if (localAi.isLocalAiEnabled()) { return await localAi.explainChineseSentence(text); } - const functions = getFunctions(); + const functions = getFunctions(getApp(), 'https://hanzigraph.com'); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const explainChinese = httpsCallable(functions, 'explainText'); const result = await explainChinese(text); @@ -737,7 +737,7 @@ async function translateEnglish(text) { if (localAi.isLocalAiEnabled()) { result = await localAi.translateEnglish(text); } else { - const functions = getFunctions(); + const functions = getFunctions(getApp(), 'https://hanzigraph.com'); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const explainEnglish = httpsCallable(functions, 'explainEnglishText'); result = await explainEnglish(text); @@ -752,7 +752,7 @@ async function generateChineseSentences(word, definitions) { if (localAi.isLocalAiEnabled()) { aiData = await localAi.generateChineseSentences(word, definitions); } else { - const functions = getFunctions(); + const functions = getFunctions(getApp(), 'https://hanzigraph.com'); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const generateChineseSentencesCall = httpsCallable(functions, 'generateChineseSentences'); aiData = await generateChineseSentencesCall({ word, definitions }); @@ -774,7 +774,7 @@ async function analyzeCollocation(collocation) { if (localAi.isLocalAiEnabled()) { aiData = await localAi.analyzeCollocation(collocation); } else { - const functions = getFunctions(); + const functions = getFunctions(getApp(), 'https://hanzigraph.com'); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const analyzeCollocationCall = httpsCallable(functions, 'analyzeCollocation'); aiData = await analyzeCollocationCall(collocation); @@ -797,7 +797,7 @@ async function analyzeImage(base64ImageContents) { if (localAi.isLocalAiEnabled()) { return await localAi.analyzeImage(base64ImageContents); } - const functions = getFunctions(); + const functions = getFunctions(getApp(), 'https://hanzigraph.com'); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const analyzeImage = httpsCallable(functions, 'analyzeImage'); const result = await analyzeImage(base64ImageContents); @@ -808,7 +808,7 @@ async function explainWordInContext(word, sentence) { if (localAi.isLocalAiEnabled()) { return await localAi.explainWordInContext(word, sentence); } - const functions = getFunctions(); + const functions = getFunctions(getApp(), 'https://hanzigraph.com'); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const explainWordInContextCall = httpsCallable(functions, 'explainWordInContext'); const result = await explainWordInContextCall({ word, sentence }); From 4aad57a1eebb75987fea84b90698a8a0c82c47d0 Mon Sep 17 00:00:00 2001 From: Matthew Reichhoff Date: Sun, 10 May 2026 13:17:28 -0400 Subject: [PATCH 2/2] use origin instead of hardcoded URL I think this is safe? Claude agrees --- public/js/modules/data-layer.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/js/modules/data-layer.js b/public/js/modules/data-layer.js index 770e75ff..58927daa 100644 --- a/public/js/modules/data-layer.js +++ b/public/js/modules/data-layer.js @@ -725,7 +725,7 @@ async function explainChineseSentence(text) { if (localAi.isLocalAiEnabled()) { return await localAi.explainChineseSentence(text); } - const functions = getFunctions(getApp(), 'https://hanzigraph.com'); + const functions = getFunctions(getApp(), window.location.origin); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const explainChinese = httpsCallable(functions, 'explainText'); const result = await explainChinese(text); @@ -737,7 +737,7 @@ async function translateEnglish(text) { if (localAi.isLocalAiEnabled()) { result = await localAi.translateEnglish(text); } else { - const functions = getFunctions(getApp(), 'https://hanzigraph.com'); + const functions = getFunctions(getApp(), window.location.origin); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const explainEnglish = httpsCallable(functions, 'explainEnglishText'); result = await explainEnglish(text); @@ -752,7 +752,7 @@ async function generateChineseSentences(word, definitions) { if (localAi.isLocalAiEnabled()) { aiData = await localAi.generateChineseSentences(word, definitions); } else { - const functions = getFunctions(getApp(), 'https://hanzigraph.com'); + const functions = getFunctions(getApp(), window.location.origin); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const generateChineseSentencesCall = httpsCallable(functions, 'generateChineseSentences'); aiData = await generateChineseSentencesCall({ word, definitions }); @@ -774,7 +774,7 @@ async function analyzeCollocation(collocation) { if (localAi.isLocalAiEnabled()) { aiData = await localAi.analyzeCollocation(collocation); } else { - const functions = getFunctions(getApp(), 'https://hanzigraph.com'); + const functions = getFunctions(getApp(), window.location.origin); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const analyzeCollocationCall = httpsCallable(functions, 'analyzeCollocation'); aiData = await analyzeCollocationCall(collocation); @@ -797,7 +797,7 @@ async function analyzeImage(base64ImageContents) { if (localAi.isLocalAiEnabled()) { return await localAi.analyzeImage(base64ImageContents); } - const functions = getFunctions(getApp(), 'https://hanzigraph.com'); + const functions = getFunctions(getApp(), window.location.origin); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const analyzeImage = httpsCallable(functions, 'analyzeImage'); const result = await analyzeImage(base64ImageContents); @@ -808,7 +808,7 @@ async function explainWordInContext(word, sentence) { if (localAi.isLocalAiEnabled()) { return await localAi.explainWordInContext(word, sentence); } - const functions = getFunctions(getApp(), 'https://hanzigraph.com'); + const functions = getFunctions(getApp(), window.location.origin); // connectFunctionsEmulator(functions, "127.0.0.1", 5001); const explainWordInContextCall = httpsCallable(functions, 'explainWordInContext'); const result = await explainWordInContextCall({ word, sentence });