ultimate-express 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yml +27 -0
- package/EXPRESS_LICENSE +26 -0
- package/README.md +269 -0
- package/package.json +76 -0
- package/src/application.js +295 -0
- package/src/index.js +23 -0
- package/src/middlewares.js +95 -0
- package/src/request.js +324 -0
- package/src/response.js +686 -0
- package/src/router.js +490 -0
- package/src/utils.js +285 -0
- package/src/view.js +103 -0
- package/src/workers/fs.js +14 -0
- package/tests/index.js +64 -0
- package/tests/parts/.test/index.html +11 -0
- package/tests/parts/big.jpg +0 -0
- package/tests/parts/index.art +12 -0
- package/tests/parts/index.dot +12 -0
- package/tests/parts/index.ejs +12 -0
- package/tests/parts/index.handlebars +2 -0
- package/tests/parts/index.html +12 -0
- package/tests/parts/index.mustache +12 -0
- package/tests/parts/index.pug +6 -0
- package/tests/parts/index.swig +12 -0
- package/tests/parts/layouts/main.handlebars +12 -0
- package/tests/preload.cjs +5 -0
- package/tests/singular.js +41 -0
- package/tests/tests/app/app-engine.js +8 -0
- package/tests/tests/app/app-on-mount.js +24 -0
- package/tests/tests/app/app-path.js +21 -0
- package/tests/tests/app/app-route.js +30 -0
- package/tests/tests/app/options.js +16 -0
- package/tests/tests/app/setting-inheritance.js +16 -0
- package/tests/tests/engines/art-template.js +33 -0
- package/tests/tests/engines/dot.js +28 -0
- package/tests/tests/engines/ejs.js +25 -0
- package/tests/tests/engines/handlebars.js +28 -0
- package/tests/tests/engines/mustache.js +28 -0
- package/tests/tests/engines/pug.js +25 -0
- package/tests/tests/engines/swig.js +28 -0
- package/tests/tests/errors/error-handling-middleware.js +22 -0
- package/tests/tests/errors/next-error-optimized.js +26 -0
- package/tests/tests/errors/next-error.js +26 -0
- package/tests/tests/errors/unexpected-error-handling.js +18 -0
- package/tests/tests/listen/listen-random.js +11 -0
- package/tests/tests/listen/listen-specific.js +17 -0
- package/tests/tests/middlewares/body-json.js +31 -0
- package/tests/tests/middlewares/body-raw-deflate.js +43 -0
- package/tests/tests/middlewares/body-raw-gzip.js +43 -0
- package/tests/tests/middlewares/body-raw.js +41 -0
- package/tests/tests/middlewares/body-text.js +27 -0
- package/tests/tests/middlewares/body-urlencoded.js +30 -0
- package/tests/tests/middlewares/cookie-parser-signed.js +31 -0
- package/tests/tests/middlewares/cookie-parser.js +28 -0
- package/tests/tests/middlewares/cookie-session.js +40 -0
- package/tests/tests/middlewares/cors.js +29 -0
- package/tests/tests/middlewares/errorhandler.js +26 -0
- package/tests/tests/middlewares/express-fileupload-temp.js +46 -0
- package/tests/tests/middlewares/express-fileupload.js +28 -0
- package/tests/tests/middlewares/express-rate-limit.js +33 -0
- package/tests/tests/middlewares/express-session.js +37 -0
- package/tests/tests/middlewares/express-static-options.js +72 -0
- package/tests/tests/middlewares/express-static.js +40 -0
- package/tests/tests/middlewares/method-override.js +33 -0
- package/tests/tests/middlewares/multer.js +43 -0
- package/tests/tests/middlewares/multiple-middlewares.js +37 -0
- package/tests/tests/middlewares/response-time.js +29 -0
- package/tests/tests/middlewares/serve-index.js +38 -0
- package/tests/tests/middlewares/serve-static.js +38 -0
- package/tests/tests/middlewares/vhost.js +50 -0
- package/tests/tests/params/array-param.js +30 -0
- package/tests/tests/params/nested-params.js +24 -0
- package/tests/tests/params/param-errors.js +56 -0
- package/tests/tests/params/param-function.js +49 -0
- package/tests/tests/params/param-next-route.js +48 -0
- package/tests/tests/params/param-optimized.js +38 -0
- package/tests/tests/params/param-use.js +39 -0
- package/tests/tests/params/param.js +68 -0
- package/tests/tests/params/params-regex.js +26 -0
- package/tests/tests/params/params-use.js +20 -0
- package/tests/tests/params/params.js +35 -0
- package/tests/tests/req/req-accepts-charsets.js +40 -0
- package/tests/tests/req/req-accepts-encodings.js +36 -0
- package/tests/tests/req/req-accepts-languages.js +41 -0
- package/tests/tests/req/req-accepts.js +41 -0
- package/tests/tests/req/req-app.js +17 -0
- package/tests/tests/req/req-baseurl.js +38 -0
- package/tests/tests/req/req-connection.js +19 -0
- package/tests/tests/req/req-fresh.js +59 -0
- package/tests/tests/req/req-get.js +78 -0
- package/tests/tests/req/req-headers-distinct.js +72 -0
- package/tests/tests/req/req-headers.js +72 -0
- package/tests/tests/req/req-host.js +45 -0
- package/tests/tests/req/req-hostname.js +45 -0
- package/tests/tests/req/req-ip.js +19 -0
- package/tests/tests/req/req-is.js +44 -0
- package/tests/tests/req/req-original-url.js +29 -0
- package/tests/tests/req/req-param.js +29 -0
- package/tests/tests/req/req-protocol.js +20 -0
- package/tests/tests/req/req-query.js +23 -0
- package/tests/tests/req/req-range.js +48 -0
- package/tests/tests/req/req-raw-headers.js +72 -0
- package/tests/tests/req/req-subdomains.js +48 -0
- package/tests/tests/req/req-url-nested.js +27 -0
- package/tests/tests/req/req-url-optimized-router.js +26 -0
- package/tests/tests/req/req-url-optimized.js +23 -0
- package/tests/tests/req/req-url.js +36 -0
- package/tests/tests/req/req-xhr.js +23 -0
- package/tests/tests/res/head-content-length.js +18 -0
- package/tests/tests/res/head.js +47 -0
- package/tests/tests/res/injecting.js +25 -0
- package/tests/tests/res/piping.js +23 -0
- package/tests/tests/res/res-app.js +17 -0
- package/tests/tests/res/res-append.js +24 -0
- package/tests/tests/res/res-attachment.js +19 -0
- package/tests/tests/res/res-clear-cookie.js +18 -0
- package/tests/tests/res/res-cookie.js +22 -0
- package/tests/tests/res/res-download.js +36 -0
- package/tests/tests/res/res-format.js +57 -0
- package/tests/tests/res/res-get.js +18 -0
- package/tests/tests/res/res-headers-sent.js +18 -0
- package/tests/tests/res/res-json.js +17 -0
- package/tests/tests/res/res-jsonp.js +25 -0
- package/tests/tests/res/res-links.js +21 -0
- package/tests/tests/res/res-location.js +34 -0
- package/tests/tests/res/res-redirect.js +46 -0
- package/tests/tests/res/res-remove-header.js +19 -0
- package/tests/tests/res/res-send-file.js +17 -0
- package/tests/tests/res/res-send-status.js +17 -0
- package/tests/tests/res/res-send.js +69 -0
- package/tests/tests/res/res-set.js +28 -0
- package/tests/tests/res/res-status.js +18 -0
- package/tests/tests/res/res-type.js +19 -0
- package/tests/tests/res/res-vary.js +19 -0
- package/tests/tests/res/res-write.js +29 -0
- package/tests/tests/routers/complex-routers.js +34 -0
- package/tests/tests/routers/empty-router.js +25 -0
- package/tests/tests/routers/lot-of-routes.js +38 -0
- package/tests/tests/routers/mergeparams.js +42 -0
- package/tests/tests/routers/nested-routers.js +52 -0
- package/tests/tests/routers/router-options.js +68 -0
- package/tests/tests/routers/routers.js +45 -0
- package/tests/tests/routers/simple-routers.js +35 -0
- package/tests/tests/routing/all.js +47 -0
- package/tests/tests/routing/array-arguments.js +35 -0
- package/tests/tests/routing/array-use.js +33 -0
- package/tests/tests/routing/async-use.js +25 -0
- package/tests/tests/routing/complex-routes.js +50 -0
- package/tests/tests/routing/lot-of-param-routes.js +26 -0
- package/tests/tests/routing/lot-of-routes.js +59 -0
- package/tests/tests/routing/next-existent-optimized-route.js +29 -0
- package/tests/tests/routing/next-existent-route.js +29 -0
- package/tests/tests/routing/next-nonexistent-optimized-route.js +19 -0
- package/tests/tests/routing/next-nonexistent-route.js +19 -0
- package/tests/tests/routing/next-special-cases.js +54 -0
- package/tests/tests/routing/next-unoptimized.js +39 -0
- package/tests/tests/routing/no-path-use.js +29 -0
- package/tests/tests/routing/non-string-routes.js +27 -0
- package/tests/tests/routing/req-multiple-mountpaths.js +34 -0
- package/tests/tests/routing/simple-routes.js +29 -0
- package/tests/tests/routing/simple-use.js +52 -0
- package/tests/tests/routing/some-middlewares.js +27 -0
- package/tests/tests/routing/special-characters.js +28 -0
- package/tests/tests/routing/star.js +31 -0
- package/tests/tests/routing/sub-apps.js +32 -0
- package/tests/tests/routing/trailing-slash.js +37 -0
- package/tests/tests/routing/weird-route-start.js +18 -0
- package/tests/tests/send-file/accept-ranges.js +26 -0
- package/tests/tests/send-file/callback.js +23 -0
- package/tests/tests/send-file/default-error-routing.js +21 -0
- package/tests/tests/send-file/dotfiles.js +24 -0
- package/tests/tests/send-file/etag.js +19 -0
- package/tests/tests/send-file/fs-threads.js +39 -0
- package/tests/tests/send-file/head.js +49 -0
- package/tests/tests/send-file/headers.js +23 -0
- package/tests/tests/send-file/if-match.js +31 -0
- package/tests/tests/send-file/if-range.js +37 -0
- package/tests/tests/send-file/if-unmodified-since.js +32 -0
- package/tests/tests/send-file/immutable.js +22 -0
- package/tests/tests/send-file/large-file.js +19 -0
- package/tests/tests/send-file/last-modified.js +21 -0
- package/tests/tests/send-file/max-age.js +21 -0
- package/tests/tests/send-file/path-traversal.js +35 -0
- package/tests/tests/send-file/range.js +57 -0
- package/tests/tests/send-file/simple.js +18 -0
- package/tests/tests/settings/case-sensitive-routing.js +48 -0
- package/tests/tests/settings/env-errors.js +38 -0
- package/tests/tests/settings/etag.js +36 -0
- package/tests/tests/settings/json-escape.js +45 -0
- package/tests/tests/settings/json-replacer.js +50 -0
- package/tests/tests/settings/json-spaces.js +44 -0
- package/tests/tests/settings/query-parser.js +45 -0
- package/tests/tests/settings/strict-routing.js +64 -0
- package/tests/tests/settings/subdomain-offset.js +38 -0
- package/tests/tests/settings/trust-proxy-host.js +58 -0
- package/tests/tests/settings/trust-proxy-ip.js +58 -0
- package/tests/tests/settings/trust-proxy-ips.js +58 -0
- package/tests/tests/settings/trust-proxy-protocol.js +46 -0
- package/tests/tests/settings/x-powered-by.js +32 -0
- package/tests/uws.js +14 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// must support res.sendFile()
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const app = express();
|
|
7
|
+
|
|
8
|
+
app.get('/test', (req, res) => {
|
|
9
|
+
res.sendFile(path.join(process.cwd(), 'src/index.js'));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.listen(13333, async () => {
|
|
13
|
+
console.log('Server is running on port 13333');
|
|
14
|
+
|
|
15
|
+
const response = await fetch('http://localhost:13333/test');
|
|
16
|
+
console.log(await response.text(), response.headers.get('Content-Type').split(';')[0]);
|
|
17
|
+
process.exit(0);
|
|
18
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// must support "case sensitive routing"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app.set('case sensitive routing', true);
|
|
8
|
+
app2.set('case sensitive routing', false);
|
|
9
|
+
|
|
10
|
+
app.get('/abc', (req, res) => {
|
|
11
|
+
res.send('hi');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
app.get('/Abc', (req, res) => {
|
|
15
|
+
res.send('bye');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app2.get('/abc', (req, res) => {
|
|
19
|
+
res.send('hi2');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app2.get('/Abc', (req, res) => {
|
|
23
|
+
res.send('bye2');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
app.listen(13333, async () => {
|
|
27
|
+
console.log('Server is running on port 13333');
|
|
28
|
+
|
|
29
|
+
let outputs = await Promise.all([
|
|
30
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
31
|
+
fetch('http://localhost:13333/Abc').then(res => res.text()),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
console.log(outputs.join(' '));
|
|
35
|
+
|
|
36
|
+
app2.listen(13334, async () => {
|
|
37
|
+
console.log('Server is running on port 13334');
|
|
38
|
+
|
|
39
|
+
let outputs2 = await Promise.all([
|
|
40
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
41
|
+
fetch('http://localhost:13334/Abc').then(res => res.text()),
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
console.log(outputs2.join(' '));
|
|
45
|
+
process.exit(0);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// must support "env" errors
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app.set('env', 'production');
|
|
8
|
+
app2.set('env', 'development');
|
|
9
|
+
|
|
10
|
+
app.get('/abc', (req, res) => {
|
|
11
|
+
throw new Error('Ignore this error, its used in a test');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
app2.get('/abc', (req, res) => {
|
|
15
|
+
throw new Error('Ignore this error, its used in a test');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.listen(13333, async () => {
|
|
19
|
+
console.log('Server is running on port 13333');
|
|
20
|
+
|
|
21
|
+
let outputs = await Promise.all([
|
|
22
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
console.log(outputs.join(' ').includes('Internal Server Error'));
|
|
26
|
+
|
|
27
|
+
app2.listen(13334, async () => {
|
|
28
|
+
console.log('Server is running on port 13334');
|
|
29
|
+
|
|
30
|
+
let outputs2 = await Promise.all([
|
|
31
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
console.log(outputs2.join(' ').includes('Ignore this error, its used in a test'));
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// must support "etag"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
const app3 = express();
|
|
8
|
+
app.set('etag', false);
|
|
9
|
+
app2.set('etag', true);
|
|
10
|
+
app3.set('etag', 'strong');
|
|
11
|
+
|
|
12
|
+
app.get('/abc', (req, res) => {
|
|
13
|
+
res.send('abc');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app2.get('/abc', (req, res) => {
|
|
17
|
+
res.send('abc');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app3.get('/abc', (req, res) => {
|
|
21
|
+
res.send('abc');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
app.listen(13333, async () => {
|
|
25
|
+
app2.listen(13334, async () => {
|
|
26
|
+
app3.listen(13335, async () => {
|
|
27
|
+
const outputs = await Promise.all([
|
|
28
|
+
fetch('http://localhost:13333/abc'),
|
|
29
|
+
fetch('http://localhost:13334/abc'),
|
|
30
|
+
fetch('http://localhost:13335/abc'),
|
|
31
|
+
]);
|
|
32
|
+
console.log(outputs.map(res => res.headers.get('etag')));
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// must support "json escape"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app.set('json escape', false);
|
|
8
|
+
app2.set('json escape', true);
|
|
9
|
+
app.get('/abc', (req, res) => {
|
|
10
|
+
res.json({ '&': '<script>' });
|
|
11
|
+
});
|
|
12
|
+
app.get('/def', (req, res) => {
|
|
13
|
+
res.jsonp({ '&': '<script>' });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app2.get('/abc', (req, res) => {
|
|
17
|
+
res.json({ '&': '<script>' });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app2.get('/def', (req, res) => {
|
|
21
|
+
res.jsonp({ '&': '<script>' });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
app.listen(13333, async () => {
|
|
25
|
+
console.log('Server is running on port 13333');
|
|
26
|
+
|
|
27
|
+
let outputs = await Promise.all([
|
|
28
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
29
|
+
fetch('http://localhost:13333/def').then(res => res.text()),
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
console.log(outputs.join(' '));
|
|
33
|
+
|
|
34
|
+
app2.listen(13334, async () => {
|
|
35
|
+
console.log('Server is running on port 13334');
|
|
36
|
+
|
|
37
|
+
let outputs2 = await Promise.all([
|
|
38
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
console.log(outputs2.join(' '));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// must support "json replacer"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app2.set('json replacer', (key, value) => {
|
|
8
|
+
if(typeof value === 'object' && value !== null) {
|
|
9
|
+
return 'REPLACED';
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
});
|
|
13
|
+
app.get('/abc', (req, res) => {
|
|
14
|
+
res.json({ test: { test: 1 } });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
app2.get('/def', (req, res) => {
|
|
18
|
+
res.jsonp({ test: { test: 1 } });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app2.get('/abc', (req, res) => {
|
|
22
|
+
res.json({ test: { test: 1 } });
|
|
23
|
+
});
|
|
24
|
+
app2.get('/def', (req, res) => {
|
|
25
|
+
res.jsonp({ test: { test: 1 } });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
app.listen(13333, async () => {
|
|
29
|
+
console.log('Server is running on port 13333');
|
|
30
|
+
|
|
31
|
+
let outputs = await Promise.all([
|
|
32
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
33
|
+
fetch('http://localhost:13333/def').then(res => res.text()),
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
console.log(outputs.join(' '));
|
|
37
|
+
|
|
38
|
+
app2.listen(13334, async () => {
|
|
39
|
+
console.log('Server is running on port 13334');
|
|
40
|
+
|
|
41
|
+
let outputs2 = await Promise.all([
|
|
42
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
43
|
+
fetch('http://localhost:13334/def').then(res => res.text()),
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
console.log(outputs2.join(' '));
|
|
47
|
+
process.exit(0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// must support "json spaces"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app2.set('json spaces', 2);
|
|
8
|
+
app.get('/abc', (req, res) => {
|
|
9
|
+
res.json({ test: { test: 1 } });
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.get('/def', (req, res) => {
|
|
13
|
+
res.jsonp({ test: { test: 1 } });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app2.get('/abc', (req, res) => {
|
|
17
|
+
res.json({ test: { test: 1 } });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app2.get('/def', (req, res) => {
|
|
21
|
+
res.jsonp({ test: { test: 1 } });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
app.listen(13333, async () => {
|
|
25
|
+
console.log('Server is running on port 13333');
|
|
26
|
+
|
|
27
|
+
let outputs = await Promise.all([
|
|
28
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
console.log(outputs.join(' '));
|
|
32
|
+
|
|
33
|
+
app2.listen(13334, async () => {
|
|
34
|
+
console.log('Server is running on port 13334');
|
|
35
|
+
|
|
36
|
+
let outputs2 = await Promise.all([
|
|
37
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
console.log(outputs2.join(' '));
|
|
41
|
+
process.exit(0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// must support "query parser"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
const app3 = express();
|
|
8
|
+
const app4 = express();
|
|
9
|
+
|
|
10
|
+
app.set('query parser', false);
|
|
11
|
+
app2.set('query parser', 'simple');
|
|
12
|
+
app3.set('query parser', 'extended');
|
|
13
|
+
app4.set('query parser', query => {
|
|
14
|
+
return {hi: 'there'};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
app.get('/abc', (req, res) => {
|
|
18
|
+
res.json(req.query);
|
|
19
|
+
});
|
|
20
|
+
app2.get('/abc', (req, res) => {
|
|
21
|
+
res.json(req.query);
|
|
22
|
+
});
|
|
23
|
+
app3.get('/abc', (req, res) => {
|
|
24
|
+
res.json(req.query);
|
|
25
|
+
});
|
|
26
|
+
app4.get('/abc', (req, res) => {
|
|
27
|
+
res.json(req.query);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
app.listen(13333, async () => {
|
|
31
|
+
app2.listen(13334, async () => {
|
|
32
|
+
app3.listen(13335, async () => {
|
|
33
|
+
app4.listen(13336, async () => {
|
|
34
|
+
let outputs = await Promise.all([
|
|
35
|
+
fetch('http://localhost:13333/abc?test=123').then(res => res.text()),
|
|
36
|
+
fetch('http://localhost:13334/abc?test=123').then(res => res.text()),
|
|
37
|
+
fetch('http://localhost:13335/abc?test=123').then(res => res.text()),
|
|
38
|
+
fetch('http://localhost:13336/abc?test=123').then(res => res.text()),
|
|
39
|
+
]);
|
|
40
|
+
console.log(outputs.join(' '));
|
|
41
|
+
process.exit(0);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// must support "strict routing"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app.set('strict routing', true);
|
|
8
|
+
app2.set('strict routing', false);
|
|
9
|
+
|
|
10
|
+
app.get("/test/:test/", (req, res) => {
|
|
11
|
+
res.send('test');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
app.get('/abc/', (req, res) => {
|
|
15
|
+
res.send('bye');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.get('/abc', (req, res) => {
|
|
19
|
+
res.send('hi');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app2.get('/abc/', (req, res) => {
|
|
23
|
+
res.send('bye2');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
app2.get('/abc', (req, res) => {
|
|
27
|
+
res.send('hi2');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
app2.use((req, res, next) => {
|
|
31
|
+
res.send('404');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
app.use((req, res, next) => {
|
|
35
|
+
res.send('404');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
app.listen(13333, async () => {
|
|
39
|
+
|
|
40
|
+
console.log('Server is running on port 13333');
|
|
41
|
+
|
|
42
|
+
let outputs = await Promise.all([
|
|
43
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
44
|
+
fetch('http://localhost:13333/abc/').then(res => res.text()),
|
|
45
|
+
fetch('http://localhost:13333/test/test/').then(res => res.text()),
|
|
46
|
+
fetch('http://localhost:13333/test/test').then(res => res.text()),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
console.log(outputs.join(' '));
|
|
51
|
+
|
|
52
|
+
app2.listen(13334, async () => {
|
|
53
|
+
console.log('Server is running on port 13334');
|
|
54
|
+
|
|
55
|
+
let outputs2 = await Promise.all([
|
|
56
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
57
|
+
fetch('http://localhost:13334/abc/').then(res => res.text()),
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
console.log(outputs2.join(' '));
|
|
61
|
+
process.exit(0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// must support "subdomain offset"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
app.set('subdomain offset', 0);
|
|
8
|
+
app2.set('subdomain offset', 1);
|
|
9
|
+
|
|
10
|
+
app.get('/abc', (req, res) => {
|
|
11
|
+
res.send(req.subdomains.join('.'));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
app2.get('/abc', (req, res) => {
|
|
15
|
+
res.send(req.subdomains.join('.'));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.listen(13333, async () => {
|
|
19
|
+
console.log('Server is running on port 13333');
|
|
20
|
+
|
|
21
|
+
let outputs = await Promise.all([
|
|
22
|
+
fetch('http://localhost:13333/abc').then(res => res.text())
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
console.log(outputs.join(' '));
|
|
26
|
+
|
|
27
|
+
app2.listen(13334, async () => {
|
|
28
|
+
console.log('Server is running on port 13334');
|
|
29
|
+
|
|
30
|
+
let outputs2 = await Promise.all([
|
|
31
|
+
fetch('http://localhost:13334/abc').then(res => res.text())
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
console.log(outputs2.join(' '));
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// must support "trust proxy" hosts
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
const app3 = express();
|
|
8
|
+
const app4 = express();
|
|
9
|
+
app.set('trust proxy', true);
|
|
10
|
+
app2.set('trust proxy', false);
|
|
11
|
+
app3.set('trust proxy', 'loopback');
|
|
12
|
+
app4.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
|
|
13
|
+
|
|
14
|
+
app.get('/abc', (req, res) => {
|
|
15
|
+
res.send(req.hostname);
|
|
16
|
+
});
|
|
17
|
+
app2.get('/abc', (req, res) => {
|
|
18
|
+
res.send(req.hostname);
|
|
19
|
+
});
|
|
20
|
+
app3.get('/abc', (req, res) => {
|
|
21
|
+
res.send(req.hostname);
|
|
22
|
+
});
|
|
23
|
+
app4.get('/abc', (req, res) => {
|
|
24
|
+
res.send(req.hostname);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(13333, async () => {
|
|
28
|
+
app2.listen(13334, async () => {
|
|
29
|
+
app3.listen(13335, async () => {
|
|
30
|
+
app4.listen(13336, async () => {
|
|
31
|
+
let outputs = await Promise.all([
|
|
32
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-Host': '127.0.0.1' } }).then(res => res.text()),
|
|
33
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-Host': '127.0.0.1' } }).then(res => res.text()),
|
|
34
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-Host': '127.0.0.1' } }).then(res => res.text()),
|
|
35
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-Host': '127.0.0.1' } }).then(res => res.text()),
|
|
36
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-Host': '192.168.1.1' } }).then(res => res.text()),
|
|
37
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-Host': '192.168.1.1' } }).then(res => res.text()),
|
|
38
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-Host': '192.168.1.1' } }).then(res => res.text()),
|
|
39
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-Host': '192.168.1.1' } }).then(res => res.text()),
|
|
40
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-Host': '10.0.0.1' } }).then(res => res.text()),
|
|
41
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-Host': '10.0.0.1' } }).then(res => res.text()),
|
|
42
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-Host': '10.0.0.1' } }).then(res => res.text()),
|
|
43
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-Host': '10.0.0.1' } }).then(res => res.text()),
|
|
44
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-Host': '172.16.0.1' } }).then(res => res.text()),
|
|
45
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-Host': '172.16.0.1' } }).then(res => res.text()),
|
|
46
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-Host': '172.16.0.1' } }).then(res => res.text()),
|
|
47
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-Host': '172.16.0.1' } }).then(res => res.text()),
|
|
48
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
49
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
50
|
+
fetch('http://localhost:13335/abc').then(res => res.text()),
|
|
51
|
+
fetch('http://localhost:13336/abc').then(res => res.text()),
|
|
52
|
+
]);
|
|
53
|
+
console.log(outputs.join(' ').replaceAll('0000:0000:0000:0000:0000:0000:0000:000', "::"));
|
|
54
|
+
process.exit(0);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// must support "trust proxy" ip
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
const app3 = express();
|
|
8
|
+
const app4 = express();
|
|
9
|
+
app.set('trust proxy', true);
|
|
10
|
+
app2.set('trust proxy', false);
|
|
11
|
+
app3.set('trust proxy', 'loopback');
|
|
12
|
+
app4.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
|
|
13
|
+
|
|
14
|
+
app.get('/abc', (req, res) => {
|
|
15
|
+
res.send(req.ip);
|
|
16
|
+
});
|
|
17
|
+
app2.get('/abc', (req, res) => {
|
|
18
|
+
res.send(req.ip);
|
|
19
|
+
});
|
|
20
|
+
app3.get('/abc', (req, res) => {
|
|
21
|
+
res.send(req.ip);
|
|
22
|
+
});
|
|
23
|
+
app4.get('/abc', (req, res) => {
|
|
24
|
+
res.send(req.ip);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(13333, async () => {
|
|
28
|
+
app2.listen(13334, async () => {
|
|
29
|
+
app3.listen(13335, async () => {
|
|
30
|
+
app4.listen(13336, async () => {
|
|
31
|
+
let outputs = await Promise.all([
|
|
32
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
33
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
34
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
35
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
36
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
37
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
38
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
39
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
40
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
41
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
42
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
43
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
44
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
45
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
46
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
47
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
48
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
49
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
50
|
+
fetch('http://localhost:13335/abc').then(res => res.text()),
|
|
51
|
+
fetch('http://localhost:13336/abc').then(res => res.text()),
|
|
52
|
+
]);
|
|
53
|
+
console.log(outputs.join(' ').replaceAll('0000:0000:0000:0000:0000:0000:0000:000', "::"));
|
|
54
|
+
process.exit(0);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// must support "trust proxy" ips
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
const app3 = express();
|
|
8
|
+
const app4 = express();
|
|
9
|
+
app.set('trust proxy', true);
|
|
10
|
+
app2.set('trust proxy', false);
|
|
11
|
+
app3.set('trust proxy', 'loopback');
|
|
12
|
+
app4.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
|
|
13
|
+
|
|
14
|
+
app.get('/abc', (req, res) => {
|
|
15
|
+
res.send(req.ips);
|
|
16
|
+
});
|
|
17
|
+
app2.get('/abc', (req, res) => {
|
|
18
|
+
res.send(req.ips);
|
|
19
|
+
});
|
|
20
|
+
app3.get('/abc', (req, res) => {
|
|
21
|
+
res.send(req.ips);
|
|
22
|
+
});
|
|
23
|
+
app4.get('/abc', (req, res) => {
|
|
24
|
+
res.send(req.ips);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(13333, async () => {
|
|
28
|
+
app2.listen(13334, async () => {
|
|
29
|
+
app3.listen(13335, async () => {
|
|
30
|
+
app4.listen(13336, async () => {
|
|
31
|
+
let outputs = await Promise.all([
|
|
32
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
33
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
34
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
35
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '127.0.0.1' } }).then(res => res.text()),
|
|
36
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
37
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
38
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
39
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '192.168.1.1' } }).then(res => res.text()),
|
|
40
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
41
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
42
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
43
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '10.0.0.1' } }).then(res => res.text()),
|
|
44
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
45
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
46
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
47
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-For': '172.16.0.1' } }).then(res => res.text()),
|
|
48
|
+
fetch('http://localhost:13333/abc').then(res => res.text()),
|
|
49
|
+
fetch('http://localhost:13334/abc').then(res => res.text()),
|
|
50
|
+
fetch('http://localhost:13335/abc').then(res => res.text()),
|
|
51
|
+
fetch('http://localhost:13336/abc').then(res => res.text()),
|
|
52
|
+
]);
|
|
53
|
+
console.log(outputs.join(' ').replaceAll('0000:0000:0000:0000:0000:0000:0000:000', "::"));
|
|
54
|
+
process.exit(0);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// must support "trust proxy" protocol
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const app2 = express();
|
|
7
|
+
const app3 = express();
|
|
8
|
+
const app4 = express();
|
|
9
|
+
app.set('trust proxy', true);
|
|
10
|
+
app2.set('trust proxy', false);
|
|
11
|
+
app3.set('trust proxy', 'loopback');
|
|
12
|
+
app4.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
|
|
13
|
+
|
|
14
|
+
app.get('/abc', (req, res) => {
|
|
15
|
+
res.send(req.protocol);
|
|
16
|
+
});
|
|
17
|
+
app2.get('/abc', (req, res) => {
|
|
18
|
+
res.send(req.protocol);
|
|
19
|
+
});
|
|
20
|
+
app3.get('/abc', (req, res) => {
|
|
21
|
+
res.send(req.protocol);
|
|
22
|
+
});
|
|
23
|
+
app4.get('/abc', (req, res) => {
|
|
24
|
+
res.send(req.protocol);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(13333, async () => {
|
|
28
|
+
app2.listen(13334, async () => {
|
|
29
|
+
app3.listen(13335, async () => {
|
|
30
|
+
app4.listen(13336, async () => {
|
|
31
|
+
let outputs = await Promise.all([
|
|
32
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-Proto': 'https' } }).then(res => res.text()),
|
|
33
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-Proto': 'https' } }).then(res => res.text()),
|
|
34
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-Proto': 'https' } }).then(res => res.text()),
|
|
35
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-Proto': 'https' } }).then(res => res.text()),
|
|
36
|
+
fetch('http://localhost:13333/abc', { headers: { 'X-Forwarded-Proto': 'http' } }).then(res => res.text()),
|
|
37
|
+
fetch('http://localhost:13334/abc', { headers: { 'X-Forwarded-Proto': 'http' } }).then(res => res.text()),
|
|
38
|
+
fetch('http://localhost:13335/abc', { headers: { 'X-Forwarded-Proto': 'http' } }).then(res => res.text()),
|
|
39
|
+
fetch('http://localhost:13336/abc', { headers: { 'X-Forwarded-Proto': 'http' } }).then(res => res.text()),
|
|
40
|
+
]);
|
|
41
|
+
console.log(outputs.join(' '));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|