function generateBrowserLoginUrl (base, token, opts = {}) { const url = new URL(`${base}/auth/token/${token}/`) if (opts.isAskFlow) { url.searchParams.append('ask', '1') } if (opts.isPrivate || opts.isAskFlow) { url.searchParams.append('private', '1') } if (opts.clearSession) { url.searchParams.append('clearSession', '1') } return url.toString() }
function getCityStateFromApi(api) { let myURL = new URL(api); let params = myURL.searchParams.get("q"); let locationary = params.split(":"); let citystate = locationary[1]; citystate = citystate.substr(1).slice(0, -1); citystate = citystate.split(","); let city = citystate[0]; let state = citystate[1]; let result = state + "-" + city + ".js"; return result; }
const urlParser = ( req, res, next ) => { if ( !req.isRoutable ) return next( false ); const urlObject = new URL( req.headers.url ); /** * url query variables convert to object * ?a=b&c=d --> {a: b, c: d} */ urlObject.searchParams.forEach( ( value, name ) => { req.query[ name ] = value; } ); req.pathname = urlObject.pathname; req.hostname = urlObject.hostname; req.href = urlObject.href; return next( true ); }
async function sendToVerfier(type, message) { try { const params = new URLSearchParams(); params.append("type", type); params.append("message", message); await fetch(VERIFIER_ADDRESS, { method: "post", body: params }) .then(res => res.json()) .then(json => json); } catch (error) { console.log(error); } }
const getAuthorizationUrl = (options = {}) => { if (!options.clientID) throw Error('clientID is empty'); if (!options.redirectUri) throw Error('redirectUri is empty'); const url = new URL(ENDPOINT_URL); url.pathname = '/auth/authorize'; url.searchParams.append('response_type', 'code'); url.searchParams.append('state', options.state || 'state'); url.searchParams.append('client_id', options.clientID); url.searchParams.append('redirect_uri', options.redirectUri); if (options.scope){ url.searchParams.append('scope', 'openid ' + options.scope); } else { url.searchParams.append('scope', 'openid'); } return url.toString(); }
it('append params to the querystring for a specified domain', function(done) { request(buildApp({ proxyAllDomains: true, appendParamToQueryString: { "example.com": [{ "regexPattern": ".", "params": { "foo": "bar" } }] } }))[methodName]('/example.com') .expect(200) .expect(function() { const hitUrl = new URL(fakeRequest.calls.argsFor(0)[0].url) expect(hitUrl.searchParams.get('foo')).toBe('bar'); }) .end(assert(done)); });
const getRequestParameters = (req) => { const { searchParams } = new url.URL(req.path, BASE); return fromEntries(searchParams.entries()); }
const getLatestTweets = (latestId) => { const url = new URL("https://api.twitter.com/1.1/search/tweets.json"); url.searchParams.append("q", "%23meinunterricht"); url.searchParams.append("count", "100"); url.searchParams.append("since_id", latestId); return new Promise((resolve, reject) => { get(url.toString()) .then((response) => { const result = JSON.parse(response.body); const tweets = parseResponse(result); const newId = tweets.length > 0 ? orderBy(tweets, "id", "desc")[0].id : latestId; resolve({newValue: newId, result: tweets}); }) .catch(err => reject(err)); }); }
it('doesnt append params to the querystring for other domains', function(done) { request(buildApp({ proxyAllDomains: true, appendParamToQueryString: { "example.com": [{ "regexPattern": ".", "params": { "foo": "bar" } }] } }))[methodName]('/example2.com') .expect(200) .expect(function() { const hitUrl = new URL(fakeRequest.calls.argsFor(0)[0].url) expect(hitUrl.searchParams.get('foo')).toBeNull(); }) .end(assert(done)); });
function getCityStateFromApi(api) { let myURL = new URL(api); let params = myURL.searchParams.get("q"); let locationary = params.split(":"); let citystate = locationary[1]; citystate = citystate.substr(1).slice(0, -1); citystate = citystate.split(","); let city = citystate[0]; let state = citystate[1]; let result = state + "-" + city + ".js"; return result; }
async function sendToIssuer(type, message) { try { const params = new URLSearchParams(); params.append("type", type); params.append("message", message); await fetch(ISSUER_ADDRESS, { method: "post", body: params }) .then(res => res.json()) .then(json => json); } catch (error) { console.log(error); } }
// Communication Functions async function sendToProver(type, message) { try { const params = new URLSearchParams(); params.append("type", type); params.append("message", message); await fetch(PROVER_ADDRESS, { method: "post", body: params }) .then(res => res.json()) .then(json => json); } catch (error) { console.log(error); } }
it('append params to the querystring for a specified domain using specified regex', function(done) { request(buildApp({ proxyAllDomains: true, appendParamToQueryString: { "example.com": [{ "regexPattern": "something", "params": { "foo": "bar" } }] } }))[methodName]('/example.com/something/else') .expect(200) .expect(function() { const hitUrl = new URL(fakeRequest.calls.argsFor(0)[0].url) expect(hitUrl.searchParams.get('foo')).toBe('bar'); }) .end(assert(done)); });