NorthwestGreenChemistry / PrISM

Questionnaire app to help clarify sustainable product design objectives.
https://www.northwestgreenchemistry.org/
MIT License
1 stars 0 forks source link

Relative path vs fixed path for flexibility #105

Open NorthDecoder opened 5 years ago

NorthDecoder commented 5 years ago

In commit 4a8ce83 there was a need to reset the path branched data is retrieved from. At some time in the future paths to resources could be set programmatically by a configuration setting

Something like (ie untested in app) :

const url = require('url');  // from nodejs v11.9.0 documentation

// Configuration
let protocol="https://";
let topLevelDomain="raw.githubusercontent.com";
let organization="/NorthwestGreenChemistry";
let repository="/PrISM";
let branch="/develop";
let directory="/app";

let orb = organization +
      repository +
      branch;

let base = protocol + topLevelDomain;
// end configuration

// define specific resource near where it is used
// maybe do not need to assign a variable like this
let resource="/assets/quiz/guiding_questions1.json";

// from nodejs v11.9.0 documentation
// new URL(input[, base])
// const myURL = new URL('/foo', 'https://example.org/');
const resourceURL = new URL(orb + directory + resource, base);

//resourceURL = base + orb + directory + resource;  // without nodejs command

//consume the URL somehow
console.log(resourceURL);
AmeliaNestler commented 5 years ago

I really like this, since it seems likely we will move this off of github at some point and it would be a lot easier to change it in one config spot than change every single link.