Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the client to reflect the PC URL used by the server. #1457

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this - so it will use the PC_URL env property set at runtime for both server and client side now.

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not need logger in this file, then let's remove this line instead of commentig it out...

const url = require('url');
const luceneEscapeQuery = require('lucene-escape-query');
const { NS_NCBI_GENE, NS_HGNC_SYMBOL, NS_UNIPROT } = require('../../../config');
Expand Down