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() }
describe('safeParseURL()', () => { it('should return null if url invalid', () => { assert(utils.safeParseURL('https://eggjs.org%0a.com') === null); assert(utils.safeParseURL('/path/for') === null); }); it('should return parsed url', () => { assert(utils.safeParseURL('https://eggjs.org').hostname === 'eggjs.org'); assert(utils.safeParseURL('https://eggjs.org!.foo.com').hostname === 'eggjs.org!.foo.com'); }); });
function checkOrigin(origin, callback) { // origin is allowed if ( typeof origin === 'undefined' || `.${new URL(origin).hostname}`.endsWith(`.${schnack_domain}`) ) { return callback(null, true); } callback(new Error('Not allowed by CORS')); }
function map(server) { server.host = new URL(server.url).host; server.location = server.name; server.distance = server.dist; return server; }
tape("allBuiltInRulesHaveValidUrl", (test) => { test.plan(132); rules.forEach(function forRule(rule) { test.ok(rule.information); test.ok(Object.getPrototypeOf(rule.information) === URL.prototype); const name = rule.names[0].toLowerCase(); test.equal( rule.information.href, `${homepage}/blob/v${version}/doc/Rules.md#${name}` ); }); test.end(); });
function getSchnackDomain() { const schnack_host = config.get('schnack_host'); try { const schnack_url = new URL(schnack_host); if (schnack_url.hostname === 'localhost') { return schnack_url.hostname; } else { const schnack_domain = schnack_url.hostname .split('.') .slice(1) .join('.'); return schnack_domain; } } catch (error) { console.error( `The schnack_host value "${schnack_host}" doesn't appear to be a proper URL. Did you forget "http://"?` ); process.exit(-1); } }
tape("someCustomRulesHaveValidUrl", (test) => { test.plan(7); customRules.all.forEach(function forRule(rule) { test.ok(!rule.information || (Object.getPrototypeOf(rule.information) === URL.prototype)); if (rule === customRules.anyBlockquote) { test.equal( rule.information.href, `${homepage}/blob/main/test/rules/any-blockquote.js` ); } else if (rule === customRules.lettersEX) { test.equal( rule.information.href, `${homepage}/blob/main/test/rules/letters-E-X.js` ); } }); test.end(); });
? new URL(req.session.redirectUrl) : new URL(FALLBACK_URL); redirectUrl.searchParams.append('authed', 'true'); if (req.authInfo && req.authInfo.message) { redirectUrl.searchParams.append( 'toastMessage', redirectUrl.searchParams.append('toastType', 'error'); secure: false, }); return res.redirect(redirectUrl.href); }, ],
const wsUrl = parsedURL.toString() const ws = websocket(wsUrl)
if (Object.getPrototypeOf(rule.information) !== URL.prototype) { result = newError("information");
get url() { if (this.opts.basicAuth) { const u = new URL(this.opts.url); u.username = this.opts.basicAuth.username || ''; u.password = this.opts.basicAuth.password || ''; return u.toString(); } return this.opts.url; }
async function run (profilerEnabled) { const port = await getPort() const url = new URL(`http://localhost:${port}/hello`) const server = await createServer(profilerEnabled, url) title(`Benchmark (enabled=${profilerEnabled})`) await getUsage(url) const net = await benchmark(url.href, 15000) const cpu = await getUsage(url) server.kill('SIGINT') return { cpu, net } }
function assertConfigReq (t, req) { const url = new URL(req.url, 'relative:///') t.equal(req.method, 'GET', 'should make a GET request') t.equal(url.pathname, '/config/v1/agents', 'should send request to /config/v1/agents') t.equal(url.search, '?service.name=my-service-name&service.environment=development', 'should encode query in query params') t.equal(req.headers.authorization, 'Bearer secret', 'should add secret token') t.equal(req.headers['user-agent'], `my-user-agent ${pkg.name}/${pkg.version} ${process.release.name}/${process.versions.node}`, 'should add proper User-Agent') }
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; }