Skip to content

Commit

Permalink
Merge pull request #1457 from PathwayCommons/iss1270_dynamic-client-envs
Browse files Browse the repository at this point in the history
Enable the client to reflect the PC URL used by the server.
  • Loading branch information
IgorRodchenkov authored Jun 8, 2024
2 parents 0749d27 + b00e510 commit 8d6dd9c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/client/features/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const { ErrorMessage } = require('../../common/components/error-message');
const { FeatureView } = require('./feature-view');
const { Contribute } = require('../../common/components/contribute');

const { PC_URL } = require('../../../config');

class Search extends React.Component {

constructor(props) {
Expand Down Expand Up @@ -67,6 +65,9 @@ class Search extends React.Component {

componentDidMount() {
this.getSearchResult();
ServerAPI.getPCURL().then(PC_URL => {
this.PC_URL = PC_URL;
});
}

onSearchValueChange(e) {
Expand Down Expand Up @@ -144,22 +145,22 @@ class Search extends React.Component {
return h('div.search', [
h('div.search-nav-links', [
h('a', {
href: PC_URL,
href: this.PC_URL,
target: '_blank'
}, 'About'),

h('a', {
href: PC_URL + '#faq',
href: this.PC_URL + '#faq',
target: '_blank'
}, 'FAQ'),

h('a', {
href: PC_URL + '#training',
href: this.PC_URL + '#training',
target: '_blank'
}, 'Training'),

h('a', {
href: PC_URL + '#data',
href: this.PC_URL + '#data',
target: '_blank'
}, 'Data'),

Expand All @@ -169,7 +170,7 @@ class Search extends React.Component {
// }, 'Tools'),

h('a', {
href: PC_URL + '#contact',
href: this.PC_URL + '#contact',
target: '_blank'
}, 'Contact'),

Expand Down
20 changes: 18 additions & 2 deletions src/client/services/server-api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const qs = require('query-string');
const _ = require('lodash');

const { PC_URL } = require('../../../config');
let PC_URL;
const { fetch } = require('../../../util');

const defaultFetchOpts = {
Expand All @@ -12,6 +12,19 @@ const defaultFetchOpts = {
};

const ServerAPI = {
getPCURL(){
if( PC_URL ){
return Promise.resolve(PC_URL);
} else {
return fetch('/api/pc/baseURL')
.then( res => res.text() )
.then( baseUrl => {
PC_URL = baseUrl;
return PC_URL;
});
}
},

// a generic method that gets pathway sbgn json from various sources
// e.g. pathwaycommons, factoid, or human created layouts
getAPIResource(opts){
Expand Down Expand Up @@ -109,7 +122,10 @@ const ServerAPI = {
},

downloadFileFromPathwayCommons( uri, format ){
return fetch(PC_URL + 'pc2/get?' + qs.stringify({ uri, format}), defaultFetchOpts);
return this.getPCURL()
.then( url => {
return fetch(url + 'pc2/get?' + qs.stringify({ uri, format}), defaultFetchOpts);
});
},

search(query){
Expand Down
5 changes: 5 additions & 0 deletions src/server/routes/pathway-commons-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const pc = require('../external-services/pathway-commons');

const router = express.Router();

const { PC_URL } = require('../../config');

router.get('/baseURL', function (req, res) {
res.send(PC_URL);
});

router.get('/search', function (req, res) {
pc.search(req.query).then(r => res.json(r));
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/search/search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const _ = require('lodash');
const logger = require('../../logger');
// const logger = require('../../logger');
const url = require('url');
const luceneEscapeQuery = require('lucene-escape-query');
const { NS_NCBI_GENE, NS_HGNC_SYMBOL, NS_UNIPROT } = require('../../../config');
Expand Down

0 comments on commit 8d6dd9c

Please sign in to comment.