UNPKG

1.15 kBJavaScriptView Raw
1/** Copyright (c) 2018 Uber Technologies, Inc.
2 *
3 * This source code is licensed under the MIT license found in the
4 * LICENSE file in the root directory of this source tree.
5 *
6 * @flow
7 */
8
9/* eslint-env node */
10
11const t = require('assert');
12const http = require('http');
13const getPort = require('get-port');
14const request = require('request-promise');
15
16const stripRoutePrefix = require('./strip-prefix.js');
17
18test('route prefix stripping', async () => {
19 const port = await getPort();
20 const expectedUrls = ['/test', '/', '/', '/', '/', '/?a=b', '/?a=b'];
21 const server = http.createServer((req, res) => {
22 stripRoutePrefix(req, '/prefix');
23 t.equal(req.url, expectedUrls.shift());
24 res.end('OK');
25 });
26 const connection = server.listen(port);
27 await request(`http://localhost:${port}/prefix/test`);
28 await request(`http://localhost:${port}/prefix/`);
29 await request(`http://localhost:${port}/prefix`);
30 await request(`http://localhost:${port}/`);
31 await request(`http://localhost:${port}`);
32 await request(`http://localhost:${port}/prefix?a=b`);
33 await request(`http://localhost:${port}?a=b`);
34 connection.close();
35});