get homeserver from windowlocation

develop
Morisse 6 years ago
parent 3a79ec30c1
commit 615ea8862e
  1. 19
      src/App.js

@ -19,11 +19,11 @@ class App extends Component {
onConnection = async () => { onConnection = async () => {
const self = this; const self = this;
const homeserver = this.getServerName();
const userName = this.state.userName; const userName = this.state.userName;
const password = this.state.password; const password = this.state.password;
try { try {
const homeserver = await this.getServerName();
// XHR POST to login // XHR POST to login
const loginRequest = await fetch( homeserver + '_matrix/client/r0/login', { const loginRequest = await fetch( homeserver + '_matrix/client/r0/login', {
method: 'POST', method: 'POST',
@ -50,10 +50,21 @@ class App extends Component {
} }
} }
getServerName() { getServerName = async () => {
return 'https://localhost:8448/'; let coreUrl = '';
const currentpage = window.location.protocol+'//'+window.location.hostname;
console.log(currentpage);
try {
const configRequest = await fetch(currentpage+'/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);
return;
}
return coreUrl;
} }
onNameChange = (evt) => { onNameChange = (evt) => {
this.setState({userName: evt.target.value}); this.setState({userName: evt.target.value});
} }

Loading…
Cancel
Save