From 83ff7741735a1e1fbab1e5186284c507c6ffbf06 Mon Sep 17 00:00:00 2001 From: Alexandre Storelli Date: Wed, 17 Oct 2018 10:31:36 +0000 Subject: [PATCH] due to CORS restrictions, fetch config.json from same domain. need symlink at install now --- src/App.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/App.js b/src/App.js index 79d8496..10783b5 100644 --- a/src/App.js +++ b/src/App.js @@ -23,9 +23,9 @@ class App extends Component { const password = this.state.password; try { - await this.getserverName(); + const path = await this.getserverName() + '_matrix/client/r0/login'; // XHR POST to login - const loginRequest = await fetch(this.state.homeserver + '_matrix/client/r0/login', { + const loginRequest = await fetch(path, { method: 'POST', body: JSON.stringify({ 'initial_device_display_name': 'Web setup account', @@ -54,23 +54,18 @@ class App extends Component { getserverName = async () => { let coreUrl = ''; - const currentPage = '//' + window.location.hostname + '/'; - console.log('old currentPage=' + currentPage); - if (currentPage.includes('-admin')) { - currentPage = currentPage.replace(/-admin/g, ''); - } - console.log('new currentPage=' + currentPage); try { - const configRequest = await fetch(currentpage + '/config.json'); + const configRequest = await fetch('/config.json'); const configData = JSON.parse(await configRequest.text()); coreUrl = configData['default_hs_url']; if (!coreUrl) throw new Error('could not get coreUrl'); } catch (e) { - console.log('error: ' + e); + console.log('coreUrl error = ' + e); return; } - console.log(coreUrl); + console.log('coreURL = ' + coreUrl); this.setState({ homeserver: coreUrl + '/' }); + return coreUrl + '/'; } onNameChange = (evt) => {