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; }
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)); });
describe("when passed a single app", () => { let server; let emitter; beforeEach(() => { server = new WebSocketServer({ port: 8088 }); }); afterEach(() => { if (emitter) emitter.close(); server.close(); }); it("subscribes to a single app", (done) => { emitter = Events.connect({ app: "myApp", url: "ws://localhost:8088/", username: "foo", password: "bar", }); server.once("connection", (conn, req) => { emitter.once("open", () => { const parts = new URL(req.url, "ws://localhost:8088/"); assert.strictEqual(parts.searchParams.get("app"), "myApp"); done(); }); }); }); });
test('success: no response (conditional)', () => { const server = http.createServer((req, res) => { serverTiming({ enabled: req => { const url = new URL(req.url, `http://${req.headers.host}`) return url.searchParams.get("debug") === "true" } })(req, res) res.setMetric('foo', 100.0) res.end('hello') }).listen(0, () => { http.get(`http://localhost:${server.address().port}/?debug=true`, mustCall((res) => { const assertStream = new AssertStream() assertStream.expect('hello') res.pipe(assertStream) assert(res.headers['server-timing']) http.get(`http://localhost:${server.address().port}/?debug=false`, mustCall((res) => { const assertStream = new AssertStream() assertStream.expect('hello') res.pipe(assertStream) assert(!res.headers['server-timing']) server.close() })) })) }) })
throw new Error('cannot connect to peer without peerAddress ("a" param)') const remotePeerAddress = uri.searchParams.get('a') uri: uri.href, peerAddressToCId: Array.from(this._conByPeerAddress.entries()), state: Array.from(this._con.keys()).map(k => this._con.get(k)), stack: (new Error('stack')).stack.split('\n').slice(1) })
outputProgress() if (urlParse.pathname === '/') { let dir = urlParse.searchParams.get('dir') if (dir === null) return void resolve() req({url: currentUrl}, (err, res, body) => { let hrefUrl = new URL(href.split('#')[0], urlParse) if (hrefUrl.pathname === '/') { let nDir = hrefUrl.searchParams.get('dir') if (!nDir) return if (nDir.startsWith(dir) && nDir.length > dir.length && !/Resources\/?$/.test(nDir)) { }) } else if (urlParse.pathname === '/view.php') { let file = urlParse.searchParams.get('id') if (file === null) return void resolve() if (/sy\.pdf$/.test(file)) return void resolve()
emitter.once("open", () => { const parts = new URL(req.url, "ws://localhost:8088/"); assert.strictEqual(parts.searchParams.get("api_key"), "foo:bar"); done(); }); emitter.once("open", () => { const parts = new URL(req.url, "ws://localhost:8088/"); assert.strictEqual(parts.searchParams.get("subscribeAll"), "true"); done(); }); emitter.once("open", () => { const parts = new URL(req.url, "ws://localhost:8088/"); assert.strictEqual(parts.searchParams.get("subscribeAll"), "false"); done(); });
it('no params appended when mismatch in regex', function(done) { request(buildApp({ proxyAllDomains: true, appendParamToQueryString: { "example.com": [{ "regexPattern": "something", "params": { "foo": "bar" } }, { "regexPattern": "nothing", "params": { "yep": "works" } } ] } }))[methodName]('/example.com/nothing/else') .expect(200) .expect(function() { const hitUrl = new URL(fakeRequest.calls.argsFor(0)[0].url) expect(hitUrl.searchParams.get('foo')).toBeNull(); expect(hitUrl.searchParams.get('yep')).toBe('works'); }) .end(assert(done)); });
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; }
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)); });
it('no params appended when mismatch in regex', function(done) { request(buildApp({ proxyAllDomains: true, appendParamToQueryString: { "example.com": [{ "regexPattern": "something", "params": { "foo": "bar" } }] } }))[methodName]('/example.com/nothing/else') .expect(200) .expect(function() { const hitUrl = new URL(fakeRequest.calls.argsFor(0)[0].url) expect(hitUrl.searchParams.get('foo')).toBeNull(); }) .end(assert(done)); });
describe("when passed multiple apps", () => { let server; let emitter; beforeEach(() => { server = new WebSocketServer({ port: 8088 }); }); afterEach(() => { emitter.close(); server.close(); }); it("subscribes to all of the apps", (done) => { emitter = Events.connect({ app: ["app1", "app2", "app3"], url: "ws://localhost:8088/", username: "foo", password: "bar", }); server.once("connection", (conn, req) => { emitter.once("open", () => { const parts = new URL(req.url, "ws://localhost:8088/"); assert.strictEqual(parts.searchParams.get("app"), "app1,app2,app3"); done(); }); }); }); });