Skip to content
Snippets Groups Projects
Commit fdb05403 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Use utils from common

parent 93e8ba31
No related branches found
No related tags found
No related merge requests found
import vars from './vars.js';
export default {
getAPiUrl: function(path = "", withPrefix = true) {
return vars.apiBaseUrl + (withPrefix ? vars.apiUrlPrefix : "") + path;
},
/**
* Parses a link header
*
* The node module parse-link-header didn't work, so https://gist.github.com/niallo/3109252 became handy
*
* @param header
*/
parseLinkHeader: (header) => {
if (header.length === 0) {
throw new Error("input must not be of zero length");
}
// Split parts by comma
const parts = header.split(',');
const links = {};
// Parse each part into a named link
for(let i=0; i<parts.length; i++) {
const section = parts[i].split(';');
if (section.length !== 2) {
throw new Error("section could not be split on ';'");
}
const url = section[0].replace(/<(.*)>/, '$1').trim();
const name = section[1].replace(/rel="(.*)"/, '$1').trim();
links[name] = url;
}
return links;
},
/**
* Parses the base url from an url
*
* @param url
* @returns {string}
*/
parseBaseUrl: (url) => {
const pathArray = url.split('/');
const protocol = pathArray[0];
const host = pathArray[2];
return protocol + '//' + host;
},
/**
* Reads a setting
*
* @param key
* @returns {*}
*/
setting: (key) => vars[key]
};
var config = undefined;
switch(process.env.BUILD) {
case "development":
config = {
apiBaseUrl: 'https://mw-dev.tugraz.at',
apiUrlPrefix: '',
keyCloakClientId: 'auth-dev-mw-frontend',
};
break;
case "production":
config = {
apiBaseUrl: 'https://mw.tugraz.at',
apiUrlPrefix: '',
keyCloakClientId: 'auth-prod-mw-frontend',
};
break;
case "demo":
config = {
apiBaseUrl: 'https://api-demo.tugraz.at',
apiUrlPrefix: '',
keyCloakClientId: 'auth-dev-mw-frontend',
};
break;
case "local":
default:
config = {
apiBaseUrl: 'http://127.0.0.1:8000',
apiUrlPrefix: '',
keyCloakClientId: 'auth-dev-mw-frontend-local',
};
}
export default config;
import utils from './utils.js';
import {i18n} from './i18n.js'; import {i18n} from './i18n.js';
import {html, LitElement} from 'lit-element'; import {html, LitElement} from 'lit-element';
import './vpu-auth'; import './vpu-auth';
...@@ -37,7 +36,7 @@ class AuthDemo extends LitElement { ...@@ -37,7 +36,7 @@ class AuthDemo extends LitElement {
<h1 class="title">Auth-Demo</h1> <h1 class="title">Auth-Demo</h1>
</div> </div>
<div class="container"> <div class="container">
<vpu-auth lang="${this.lang}" client-id="${utils.setting('keyCloakClientId')}" load-person></vpu-auth> <vpu-auth lang="${this.lang}" client-id="${commonUtils.setting('keyCloakClientId')}" load-person></vpu-auth>
</div> </div>
</section> </section>
`; `;
......
import {i18n} from './i18n.js'; import {i18n} from './i18n.js';
import {html, LitElement} from 'lit-element'; import {html, LitElement} from 'lit-element';
import JSONLD from 'vpu-common/jsonld' import JSONLD from 'vpu-common/jsonld'
import utils from "./utils";
import commonUtils from 'vpu-common/utils'; import commonUtils from 'vpu-common/utils';
/** /**
...@@ -94,7 +93,7 @@ class VPUAuth extends LitElement { ...@@ -94,7 +93,7 @@ class VPUAuth extends LitElement {
that.dispatchInitEvent(); that.dispatchInitEvent();
if (that.loadPerson) { if (that.loadPerson) {
JSONLD.initialize(utils.getAPiUrl(), (jsonld) => { JSONLD.initialize(commonUtils.getAPiUrl(), (jsonld) => {
// find the correct api url for the current person // find the correct api url for the current person
// we are fetching the logged-in person directly to respect the REST philosophy // we are fetching the logged-in person directly to respect the REST philosophy
// see: https://github.com/api-platform/api-platform/issues/337 // see: https://github.com/api-platform/api-platform/issues/337
......
common @ fdcb4c14
Subproject commit 378256b0ae92712fd5b8feed3a987cd014617c0b Subproject commit fdcb4c14ef0375b5dc61d48ca4f59bd6c2561708
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment