Skip to content

Commit cb7992d

Browse files
committed
chore: dynamic proxy config comunicates acount server url to use for phoenix local dev
1 parent 6b42f3a commit cb7992d

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

serve-proxy.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@ const server = http.createServer((req, res) => {
270270
return;
271271
}
272272

273+
// Handle proxy config request
274+
if (parsedUrl.pathname === '/proxy/config') {
275+
const configResponse = {
276+
accountURL: accountServer + '/'
277+
};
278+
279+
if (!config.silent) {
280+
console.log(`[CONFIG] ${req.method} ${parsedUrl.pathname} -> ${JSON.stringify(configResponse)}`);
281+
}
282+
283+
const headers = {
284+
'Content-Type': 'application/json'
285+
};
286+
287+
if (config.cors) {
288+
headers['Access-Control-Allow-Origin'] = '*';
289+
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS';
290+
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Cache-Control';
291+
}
292+
293+
res.writeHead(200, headers);
294+
res.end(JSON.stringify(configResponse));
295+
return;
296+
}
297+
273298
// Check if this is a proxy request
274299
if (parsedUrl.pathname.startsWith('/proxy/accounts')) {
275300
// Extract the path after /proxy/accounts

src/brackets.config.staging.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"bugsnagEnv" : "staging",
1111
"app_notification_url" : "https://updates.phcode.io/appNotifications/staging/",
1212
"app_update_url" : "https://updates.phcode.io/tauri/update-latest-pre-release.json",
13-
"promotions_url" : "https://promotions.phcode.dev/dev/"
13+
"promotions_url" : "https://promotions.phcode.dev/dev/",
14+
"account_url" : "https://account-stage.phcode.dev/"
1415
}

src/index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,22 @@
446446
loadJS('verify-dependencies-loaded.js', null, document.body);
447447
}
448448

449-
function _startRequireLoop() {
449+
async function _startRequireLoop() {
450+
// If running on localhost, fetch proxy config to get dynamic account URL
451+
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
452+
try {
453+
const response = await fetch('/proxy/config');
454+
if (response.ok) {
455+
const config = await response.json();
456+
if (config.accountURL) {
457+
window.AppConfig.config.account_url = config.accountURL;
458+
console.log('Applied dynamic account URL from proxy:', config.accountURL);
459+
}
460+
}
461+
} catch (error) {
462+
console.warn('Failed to fetch proxy config, using default account URL:', error);
463+
}
464+
}
450465
loadJS('thirdparty/requirejs/require.js', _requireDone, document.body, "main");
451466
}
452467
if(window.PhStore){

src/utils/Global.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
define(function (require, exports, module) {
2929

3030

31-
var configJSON = require("text!config.json"),
32-
UrlParams = require("utils/UrlParams").UrlParams;
31+
const UrlParams = require("utils/UrlParams").UrlParams;
3332

3433
// Define core brackets namespace if it isn't already defined
3534
//
@@ -57,7 +56,7 @@ define(function (require, exports, module) {
5756

5857
// Parse src/config.json
5958
try {
60-
global.brackets.metadata = JSON.parse(configJSON);
59+
global.brackets.metadata = window.AppConfig;
6160
global.brackets.config = global.brackets.metadata.config;
6261
} catch (err) {
6362
console.log(err);

test/SpecRunner.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<!-- Import the phoenix browser virtual file system -->
149149
<script src="../src/phoenix/virtualfs.js"></script>
150150
<script src="../src/utils/EventDispatcher.js"></script>
151+
<script src="../src/appConfig.js"></script>
151152

152153
<script>
153154
// environment setup for boot. do not move out of index html!!

0 commit comments

Comments
 (0)