|
3 | 3 | const http = require('http'), |
4 | 4 | log = console.log; |
5 | 5 |
|
6 | | -print(new URL('http://wangding:[email protected]:8080/a/b/c?age=20&gender=M#/d/e/f')); |
| 6 | +const addr = new URL('http://wangding:[email protected]:8080/a/b/c?age=20&gender=M#/d/e/f'); |
| 7 | +const [age, gender] = addr.searchParams.values(); |
7 | 8 |
|
8 | | -http.createServer((req, res) => { |
9 | | - console.log('req URL:\t', req.url); |
10 | | - |
11 | | - print(new URL(req.url, `http://${req.headers.host}`)); |
| 9 | +log(addr); |
| 10 | +log(`pathname: ${addr.pathname}`); |
| 11 | +log(`age: ${age}\ngender: ${gender}`); |
12 | 12 |
|
| 13 | +http.createServer((req, res) => { |
| 14 | + log('req URL:', req.url); |
| 15 | + log(new URL(req.url, `http://${req.headers.host}`)); |
13 | 16 | res.end('ok!'); |
14 | 17 | }).listen(8080); |
15 | | - |
16 | | -function print(url) { |
17 | | - log('href:\t\t', url.href); |
18 | | - log('protocol:\t', url.protocol); |
19 | | - log('username:\t', url.username); |
20 | | - log('password:\t', url.password); |
21 | | - log('hostname:\t', url.hostname); |
22 | | - log('port:\t\t', url.port); |
23 | | - log('host:\t\t', url.host); |
24 | | - log('pathname:\t', url.pathname); |
25 | | - log('search:\t\t', url.search); |
26 | | - log('hash:\t\t', url.hash); |
27 | | - |
28 | | - log('pathname parse:\t', url.pathname.split('/')); |
29 | | - log('age:\t\t', url.searchParams.get('age')); |
30 | | - log('gender:\t\t', url.searchParams.get('gender')); |
31 | | - log(); |
32 | | -} |
0 commit comments