1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const t = require('assert');
|
12 | const http = require('http');
|
13 | const getPort = require('get-port');
|
14 | const request = require('request-promise');
|
15 |
|
16 | const stripRoutePrefix = require('./strip-prefix.js');
|
17 |
|
18 | test('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 | });
|