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,30 @@
|
|
|
1
|
+
// must support array app.param
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.param(['id', 'id2'], (req, res, next, value, key) => {
|
|
8
|
+
console.log('CALLED ONLY ONCE', value, key);
|
|
9
|
+
next();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.get('/user/:id', (req, res) => {
|
|
13
|
+
res.send('user');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.get('/test/:id2', (req, res) => {
|
|
17
|
+
res.send('test');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.listen(13333, async () => {
|
|
21
|
+
console.log('Server is running on port 13333');
|
|
22
|
+
|
|
23
|
+
const response = await fetch('http://localhost:13333/user/123');
|
|
24
|
+
console.log(response.status);
|
|
25
|
+
const response2 = await fetch('http://localhost:13333/test/123');
|
|
26
|
+
console.log(response2.status);
|
|
27
|
+
const response3 = await fetch('http://localhost:13333/user/555');
|
|
28
|
+
console.log(response3.status);
|
|
29
|
+
process.exit(0);
|
|
30
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// must match nested params express behavior
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express.Router();
|
|
7
|
+
const router2 = express.Router();
|
|
8
|
+
const router3 = express.Router();
|
|
9
|
+
|
|
10
|
+
app.use("/:id1", router);
|
|
11
|
+
router.use("/test", router2);
|
|
12
|
+
router2.use("/:id3", router3);
|
|
13
|
+
router3.get("/:test/:test2", (req, res) => {
|
|
14
|
+
res.send(`${req.params.id1}-test-${req.params.id3}-${req.params.test}-${req.params.test2}`); // undefined-test-undefined-test-asdf
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
app.listen(13333, async () => {
|
|
18
|
+
console.log('Server is running on port 13333');
|
|
19
|
+
|
|
20
|
+
let res = await fetch('http://localhost:13333/1/test/2/test/asdf');
|
|
21
|
+
console.log(await res.text());
|
|
22
|
+
|
|
23
|
+
process.exit(0);
|
|
24
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// must support param errors
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express.Router();
|
|
7
|
+
|
|
8
|
+
app.param('id', (req, res, next, value, key) => {
|
|
9
|
+
if(value === '555') {
|
|
10
|
+
return res.send('bypassed');
|
|
11
|
+
}
|
|
12
|
+
if(value === '333') {
|
|
13
|
+
return next(new Error('test error'));
|
|
14
|
+
}
|
|
15
|
+
next();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.get('/user/:id', function (req, res, next) {
|
|
19
|
+
console.log('this matches');
|
|
20
|
+
next();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.get('/user/:id', function (req, res) {
|
|
24
|
+
console.log('and this matches too');
|
|
25
|
+
res.send('test');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
router.param('id', function (req, res, next, id) {
|
|
29
|
+
console.log('Router param call');
|
|
30
|
+
next();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
router.get('/:id', (req, res) => {
|
|
34
|
+
res.send('routertest');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
app.use('/test', router);
|
|
38
|
+
|
|
39
|
+
app.use((err, req, res, next) => {
|
|
40
|
+
res.send(err.message);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
app.listen(13333, async () => {
|
|
44
|
+
console.log('Server is running on port 13333');
|
|
45
|
+
|
|
46
|
+
const response = await fetch('http://localhost:13333/user/123');
|
|
47
|
+
console.log(response.status);
|
|
48
|
+
const response2 = await fetch('http://localhost:13333/test/123');
|
|
49
|
+
console.log(response2.status);
|
|
50
|
+
const response3 = await fetch('http://localhost:13333/user/333');
|
|
51
|
+
console.log(await response3.text());
|
|
52
|
+
const response4 = await fetch('http://localhost:13333/user/555').then(res => res.text());
|
|
53
|
+
console.log(response4);
|
|
54
|
+
|
|
55
|
+
process.exit(0);
|
|
56
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// must support app.param and router.param as function
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express.Router();
|
|
7
|
+
|
|
8
|
+
app.param(function (param, option) {
|
|
9
|
+
return function (req, res, next, val) {
|
|
10
|
+
console.log('param', param, option);
|
|
11
|
+
next();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.get("/user/:id", (req, res, next) => {
|
|
16
|
+
console.log('before');
|
|
17
|
+
next();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.param('id', 1337);
|
|
21
|
+
|
|
22
|
+
app.get('/user/:id', function (req, res, next) {
|
|
23
|
+
console.log('although this matches');
|
|
24
|
+
next();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.get('/user/:id', function (req, res) {
|
|
28
|
+
console.log('and this matches too');
|
|
29
|
+
res.send('test');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
router.get('/:id', (req, res) => {
|
|
33
|
+
res.send('routertest');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
app.use('/test', router);
|
|
37
|
+
|
|
38
|
+
app.listen(13333, async () => {
|
|
39
|
+
console.log('Server is running on port 13333');
|
|
40
|
+
|
|
41
|
+
const response = await fetch('http://localhost:13333/user/123');
|
|
42
|
+
console.log(response.status);
|
|
43
|
+
const response2 = await fetch('http://localhost:13333/test/123');
|
|
44
|
+
console.log(response2.status);
|
|
45
|
+
const response3 = await fetch('http://localhost:13333/user/555').then(res => res.text());
|
|
46
|
+
console.log(response3);
|
|
47
|
+
|
|
48
|
+
process.exit(0);
|
|
49
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// must support next('route') in param
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.param('id', (req, res, next, value, key) => {
|
|
8
|
+
console.log('param 1');
|
|
9
|
+
if(value === '333') {
|
|
10
|
+
return next('route');
|
|
11
|
+
}
|
|
12
|
+
next();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.param('id', (req, res, next, value, key) => {
|
|
16
|
+
console.log('param 2');
|
|
17
|
+
next();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.get('/user/:id', [
|
|
21
|
+
function (req, res, next) {
|
|
22
|
+
console.log('route 1');
|
|
23
|
+
res.send(req.params.id);
|
|
24
|
+
},
|
|
25
|
+
function (req, res, next) {
|
|
26
|
+
console.log('route 2');
|
|
27
|
+
res.send(req.params.id);
|
|
28
|
+
},
|
|
29
|
+
function (req, res, next) {
|
|
30
|
+
console.log('route 3');
|
|
31
|
+
res.send(req.params.id);
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
app.use((err, req, res, next) => {
|
|
36
|
+
res.send(err.message);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
app.listen(13333, async () => {
|
|
40
|
+
console.log('Server is running on port 13333');
|
|
41
|
+
|
|
42
|
+
const response = await fetch('http://localhost:13333/user/555').then(res => res.text());
|
|
43
|
+
console.log(response);
|
|
44
|
+
const response2 = await fetch('http://localhost:13333/user/333').then(res => res.text());
|
|
45
|
+
console.log(response2);
|
|
46
|
+
|
|
47
|
+
process.exit(0);
|
|
48
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// must support optimized app.param
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.param('test', async function (req, res, next, id) {
|
|
8
|
+
console.log('param:', id);
|
|
9
|
+
if(id === 'test') {
|
|
10
|
+
next('route');
|
|
11
|
+
} else {
|
|
12
|
+
next();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.use("/:test", (req, res, next) => {
|
|
17
|
+
console.log('match', req.url);
|
|
18
|
+
next();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.get("/test", (req, res) => {
|
|
22
|
+
res.send(req.url);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
app.get("/toast", (req, res) => {
|
|
26
|
+
res.send(req.url);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
app.listen(13333, async () => {
|
|
30
|
+
console.log('Server is running on port 13333');
|
|
31
|
+
|
|
32
|
+
let res;
|
|
33
|
+
res = await fetch('http://localhost:13333/test');
|
|
34
|
+
console.log(await res.text());
|
|
35
|
+
res = await fetch('http://localhost:13333/toast');
|
|
36
|
+
console.log(await res.text());
|
|
37
|
+
process.exit(0);
|
|
38
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// must support param on use
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express.Router();
|
|
7
|
+
|
|
8
|
+
app.param('id', (req, res, next, value, key) => {
|
|
9
|
+
if(value === '555') {
|
|
10
|
+
return next('route');
|
|
11
|
+
}
|
|
12
|
+
console.log('id:', value);
|
|
13
|
+
next();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
router.get('/test', (req, res, next) => {
|
|
17
|
+
return res.send('router');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.use('/:id', router);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
app.use((req, res, next) => {
|
|
24
|
+
return res.send('bypassed');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(13333, async () => {
|
|
28
|
+
|
|
29
|
+
console.log('Server is running on port 13333');
|
|
30
|
+
|
|
31
|
+
const response = await fetch('http://localhost:13333/1/test');
|
|
32
|
+
console.log(await response.text());
|
|
33
|
+
|
|
34
|
+
const response2 = await fetch('http://localhost:13333/555/test');
|
|
35
|
+
console.log(await response2.text());
|
|
36
|
+
|
|
37
|
+
process.exit(0);
|
|
38
|
+
|
|
39
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// must support app.param and router.param
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express.Router();
|
|
7
|
+
|
|
8
|
+
app.get("/user/:id", (req, res, next) => {
|
|
9
|
+
console.log('before');
|
|
10
|
+
next();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.param('id', (req, res, next, value, key) => {
|
|
14
|
+
if(value === '555') {
|
|
15
|
+
return res.send('bypassed');
|
|
16
|
+
}
|
|
17
|
+
next();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.param('id', function (req, res, next, value, key) {
|
|
21
|
+
console.log('CALLED ONLY ONCE', value, key);
|
|
22
|
+
next();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
app.param('id', function (req, res, next, id) {
|
|
26
|
+
console.log('test 2');
|
|
27
|
+
next();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
app.param('id', async function (req, res, next, id) {
|
|
31
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
32
|
+
console.log('test 3');
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
app.get('/user/:id', function (req, res, next) {
|
|
37
|
+
console.log('although this matches');
|
|
38
|
+
next();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
app.get('/user/:id', function (req, res) {
|
|
42
|
+
console.log('and this matches too');
|
|
43
|
+
res.send('test');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
router.param('id', function (req, res, next, id) {
|
|
47
|
+
console.log('Router param call');
|
|
48
|
+
next();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
router.get('/:id', (req, res) => {
|
|
52
|
+
res.send('routertest');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
app.use('/test', router);
|
|
56
|
+
|
|
57
|
+
app.listen(13333, async () => {
|
|
58
|
+
console.log('Server is running on port 13333');
|
|
59
|
+
|
|
60
|
+
const response = await fetch('http://localhost:13333/user/123');
|
|
61
|
+
console.log(response.status);
|
|
62
|
+
const response2 = await fetch('http://localhost:13333/test/123');
|
|
63
|
+
console.log(response2.status);
|
|
64
|
+
const response3 = await fetch('http://localhost:13333/user/555').then(res => res.text());
|
|
65
|
+
console.log(response3);
|
|
66
|
+
|
|
67
|
+
process.exit(0);
|
|
68
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// must support param regex
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test/:id(t\\d+t)', (req, res) => {
|
|
8
|
+
res.send(`id: ${req.params.id}`);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.use((req, res) => {
|
|
12
|
+
res.status(404).send(`404`);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.listen(13333, async () => {
|
|
16
|
+
console.log('Server is running on port 13333');
|
|
17
|
+
|
|
18
|
+
let outputs = await Promise.all([
|
|
19
|
+
fetch('http://localhost:13333/test/').then(res => res.text()),
|
|
20
|
+
fetch('http://localhost:13333/test/t123t').then(res => res.text()),
|
|
21
|
+
fetch('http://localhost:13333/test/f').then(res => res.text()),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
console.log(outputs.join(' '));
|
|
25
|
+
process.exit(0);
|
|
26
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// must support params in use
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.use('/:id', (req, res) => {
|
|
8
|
+
res.send(`id: ${req.params.id}`);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.listen(13333, async () => {
|
|
12
|
+
console.log('Server is running on port 13333');
|
|
13
|
+
|
|
14
|
+
let outputs = await Promise.all([
|
|
15
|
+
fetch('http://localhost:13333/123').then(res => res.text()),
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
console.log(outputs.join(' '));
|
|
19
|
+
process.exit(0);
|
|
20
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// must support params
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/:id', (req, res) => {
|
|
8
|
+
res.send(`id: ${req.params.id}`);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.get('/:id/test', (req, res) => {
|
|
12
|
+
res.send(`testid: ${req.params.id}`);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.get('/:id/test/:testid', (req, res) => {
|
|
16
|
+
res.send(`id: ${req.params.id} testid: ${req.params.testid}`);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
app.get('/:id/test/:testid/testy', (req, res) => {
|
|
20
|
+
res.send(`id: ${req.params.id} testid: ${req.params.testid}`);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.listen(13333, async () => {
|
|
24
|
+
console.log('Server is running on port 13333');
|
|
25
|
+
|
|
26
|
+
let outputs = await Promise.all([
|
|
27
|
+
fetch('http://localhost:13333/123').then(res => res.text()),
|
|
28
|
+
fetch('http://localhost:13333/456/test').then(res => res.text()),
|
|
29
|
+
fetch('http://localhost:13333/789/test/123').then(res => res.text()),
|
|
30
|
+
fetch('http://localhost:13333/456/test/789/testy').then(res => res.text()),
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
console.log(outputs.join(' '));
|
|
34
|
+
process.exit(0);
|
|
35
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// must support req.acceptsCharsets()
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test', (req, res) => {
|
|
8
|
+
console.log(req.acceptsCharsets('utf-8'));
|
|
9
|
+
console.log(req.acceptsCharsets('utf-8', 'utf-16'));
|
|
10
|
+
console.log(req.acceptsCharsets('utf-8', 'utf-16', 'utf-32'));
|
|
11
|
+
console.log(req.acceptsCharsets('utf-8', 'utf-16', 'utf-32', 'utf-16'));
|
|
12
|
+
res.send('test');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.listen(13333, async () => {
|
|
16
|
+
console.log('Server is running on port 13333');
|
|
17
|
+
|
|
18
|
+
await fetch('http://localhost:13333/test').then(res => res.text());
|
|
19
|
+
await fetch('http://localhost:13333/test', {
|
|
20
|
+
headers: {
|
|
21
|
+
'Accept-Charset': 'utf-8'
|
|
22
|
+
}
|
|
23
|
+
}).then(res => res.text());
|
|
24
|
+
await fetch('http://localhost:13333/test', {
|
|
25
|
+
headers: {
|
|
26
|
+
'Accept-Charset': 'utf-8, utf-16'
|
|
27
|
+
}
|
|
28
|
+
}).then(res => res.text());
|
|
29
|
+
await fetch('http://localhost:13333/test', {
|
|
30
|
+
headers: {
|
|
31
|
+
'Accept-Charset': 'utf-32'
|
|
32
|
+
}
|
|
33
|
+
}).then(res => res.text());
|
|
34
|
+
await fetch('http://localhost:13333/test', {
|
|
35
|
+
headers: {
|
|
36
|
+
'Accept-Charset': 'utf-16, utf-32, utf-16'
|
|
37
|
+
}
|
|
38
|
+
}).then(res => res.text());
|
|
39
|
+
process.exit(0);
|
|
40
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// must support req.acceptsEncodings()
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test', (req, res) => {
|
|
8
|
+
console.log(req.acceptsEncodings('gzip'));
|
|
9
|
+
console.log(req.acceptsEncodings('gzip', 'deflate'));
|
|
10
|
+
console.log(req.acceptsEncodings('gzip', 'deflate', 'br'));
|
|
11
|
+
console.log(req.acceptsEncodings('gzip', 'deflate', 'br', 'deflate'));
|
|
12
|
+
console.log(req.acceptsEncodings('deflate', 'br', 'deflate', 'gzip'));
|
|
13
|
+
res.send('test');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.listen(13333, async () => {
|
|
17
|
+
console.log('Server is running on port 13333');
|
|
18
|
+
|
|
19
|
+
await fetch('http://localhost:13333/test').then(res => res.text());
|
|
20
|
+
await fetch('http://localhost:13333/test', {
|
|
21
|
+
headers: {
|
|
22
|
+
'Accept-Encoding': 'gzip'
|
|
23
|
+
}
|
|
24
|
+
}).then(res => res.text());
|
|
25
|
+
await fetch('http://localhost:13333/test', {
|
|
26
|
+
headers: {
|
|
27
|
+
'Accept-Encoding': 'gzip, deflate'
|
|
28
|
+
}
|
|
29
|
+
}).then(res => res.text());
|
|
30
|
+
await fetch('http://localhost:13333/test', {
|
|
31
|
+
headers: {
|
|
32
|
+
'Accept-Encoding': 'deflate, br'
|
|
33
|
+
}
|
|
34
|
+
}).then(res => res.text());
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// must support req.acceptsLanguages()
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test', (req, res) => {
|
|
8
|
+
console.log(req.acceptsLanguages('en'));
|
|
9
|
+
console.log(req.acceptsLanguages('en', 'fr'));
|
|
10
|
+
console.log(req.acceptsLanguages('en', 'fr', 'de'));
|
|
11
|
+
console.log(req.acceptsLanguages('en', 'fr', 'de', 'fr'));
|
|
12
|
+
console.log(req.acceptsLanguages('fr', 'de', 'fr', 'en'));
|
|
13
|
+
res.send('test');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.listen(13333, async () => {
|
|
17
|
+
console.log('Server is running on port 13333');
|
|
18
|
+
|
|
19
|
+
await fetch('http://localhost:13333/test').then(res => res.text());
|
|
20
|
+
await fetch('http://localhost:13333/test', {
|
|
21
|
+
headers: {
|
|
22
|
+
'Accept-Language': 'en'
|
|
23
|
+
}
|
|
24
|
+
}).then(res => res.text());
|
|
25
|
+
await fetch('http://localhost:13333/test', {
|
|
26
|
+
headers: {
|
|
27
|
+
'Accept-Language': 'en, fr'
|
|
28
|
+
}
|
|
29
|
+
}).then(res => res.text());
|
|
30
|
+
await fetch('http://localhost:13333/test', {
|
|
31
|
+
headers: {
|
|
32
|
+
'Accept-Language': 'fr, de'
|
|
33
|
+
}
|
|
34
|
+
}).then(res => res.text());
|
|
35
|
+
await fetch('http://localhost:13333/test', {
|
|
36
|
+
headers: {
|
|
37
|
+
'Accept-Language': 'en, fr, de, fr'
|
|
38
|
+
}
|
|
39
|
+
}).then(res => res.text());
|
|
40
|
+
process.exit(0);
|
|
41
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// must support req.accepts()
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test', (req, res) => {
|
|
8
|
+
console.log(req.accepts('html'));
|
|
9
|
+
console.log(req.accepts('json'));
|
|
10
|
+
console.log(req.accepts('text'));
|
|
11
|
+
console.log(req.accepts('*/*'));
|
|
12
|
+
console.log(req.accepts('application/json'));
|
|
13
|
+
console.log(req.accepts('text/html'));
|
|
14
|
+
console.log(req.accepts(['json', 'text']));
|
|
15
|
+
console.log(req.accepts(['json', 'html']));
|
|
16
|
+
console.log(req.accepts(['html', 'json']));
|
|
17
|
+
res.send('test');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.listen(13333, async () => {
|
|
21
|
+
console.log('Server is running on port 13333');
|
|
22
|
+
|
|
23
|
+
await fetch('http://localhost:13333/test').then(res => res.text());
|
|
24
|
+
await fetch('http://localhost:13333/test', {
|
|
25
|
+
headers: {
|
|
26
|
+
'Accept': 'text/html'
|
|
27
|
+
}
|
|
28
|
+
}).then(res => res.text());
|
|
29
|
+
await fetch('http://localhost:13333/test', {
|
|
30
|
+
headers: {
|
|
31
|
+
'Accept': 'application/json'
|
|
32
|
+
}
|
|
33
|
+
}).then(res => res.text());
|
|
34
|
+
await fetch('http://localhost:13333/test', {
|
|
35
|
+
headers: {
|
|
36
|
+
'Accept': 'text/plain'
|
|
37
|
+
}
|
|
38
|
+
}).then(res => res.text());
|
|
39
|
+
|
|
40
|
+
process.exit(0);
|
|
41
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// must support req.app
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test', (req, res) => {
|
|
8
|
+
console.log(!!req.app);
|
|
9
|
+
res.send('test');
|
|
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').then(res => res.text());
|
|
16
|
+
process.exit(0);
|
|
17
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// must support req.baseUrl
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const greet = express.Router()
|
|
7
|
+
|
|
8
|
+
greet.get('/jp', function (req, res) {
|
|
9
|
+
res.send(req.baseUrl)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.use(['/gre+t', '/hel{2}o'], greet);
|
|
13
|
+
|
|
14
|
+
app.use('/greet', (req, res, next) => {
|
|
15
|
+
res.send(req.baseUrl);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.use((req, res, next) => {
|
|
19
|
+
res.send('404');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app.listen(13333, async () => {
|
|
23
|
+
console.log('Server is running on port 13333');
|
|
24
|
+
|
|
25
|
+
let res = await fetch('http://localhost:13333/greet/jp');
|
|
26
|
+
console.log(await res.text());
|
|
27
|
+
|
|
28
|
+
res = await fetch('http://localhost:13333/hello/jp');
|
|
29
|
+
console.log(await res.text());
|
|
30
|
+
|
|
31
|
+
res = await fetch('http://localhost:13333/greet/fsg');
|
|
32
|
+
console.log(await res.text());
|
|
33
|
+
|
|
34
|
+
// res = await fetch('http://localhost:13333/greet/test');
|
|
35
|
+
// console.log(await res.text());
|
|
36
|
+
|
|
37
|
+
process.exit(0);
|
|
38
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// must support req.connection and req.socket
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/test', (req, res) => {
|
|
8
|
+
console.log(req.connection.remoteAddress.replace("0000:0000:0000:0000:0000:0000:0000:000", "::"));
|
|
9
|
+
console.log(req.connection.localPort);
|
|
10
|
+
res.send('test');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.listen(13333, async () => {
|
|
14
|
+
console.log('Server is running on port 13333');
|
|
15
|
+
|
|
16
|
+
await fetch('http://localhost:13333/test').then(res => res.text());
|
|
17
|
+
|
|
18
|
+
process.exit(0);
|
|
19
|
+
});
|