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,47 @@
|
|
|
1
|
+
// must support app.all
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.all('/test', (req, res) => {
|
|
8
|
+
res.send('test');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.use((req, res) => {
|
|
12
|
+
res.send('404');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.listen(13333, async () => {
|
|
16
|
+
console.log('Server is running on port 13333');
|
|
17
|
+
|
|
18
|
+
let res = await fetch('http://localhost:13333/test');
|
|
19
|
+
console.log(await res.text());
|
|
20
|
+
|
|
21
|
+
res = await fetch('http://localhost:13333/test', {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
});
|
|
24
|
+
console.log(await res.text());
|
|
25
|
+
|
|
26
|
+
res = await fetch('http://localhost:13333/test', {
|
|
27
|
+
method: 'PUT',
|
|
28
|
+
});
|
|
29
|
+
console.log(await res.text());
|
|
30
|
+
|
|
31
|
+
res = await fetch('http://localhost:13333/test', {
|
|
32
|
+
method: 'DELETE',
|
|
33
|
+
});
|
|
34
|
+
console.log(await res.text());
|
|
35
|
+
|
|
36
|
+
res = await fetch('http://localhost:13333/test', {
|
|
37
|
+
method: 'PATCH',
|
|
38
|
+
});
|
|
39
|
+
console.log(await res.text());
|
|
40
|
+
|
|
41
|
+
res = await fetch('http://localhost:13333/testas', {
|
|
42
|
+
method: 'OPTIONS',
|
|
43
|
+
});
|
|
44
|
+
console.log(await res.text());
|
|
45
|
+
|
|
46
|
+
process.exit(0);
|
|
47
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// must support array arguments
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.use([(req, res, next) => {
|
|
8
|
+
console.log('first');
|
|
9
|
+
next();
|
|
10
|
+
}, (req, res, next) => {
|
|
11
|
+
console.log('second');
|
|
12
|
+
next();
|
|
13
|
+
}]);
|
|
14
|
+
|
|
15
|
+
app.use('/asdf', (req, res, next) => {
|
|
16
|
+
console.log('third');
|
|
17
|
+
next();
|
|
18
|
+
}, (req, res, next) => {
|
|
19
|
+
console.log('fourth');
|
|
20
|
+
next();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.get('/asdf', (req, res) => {
|
|
24
|
+
res.send('asdf');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
app.listen(13333, async () => {
|
|
29
|
+
console.log('Server is running on port 13333');
|
|
30
|
+
|
|
31
|
+
let output = await fetch('http://localhost:13333/asdf').then(res => res.text());
|
|
32
|
+
|
|
33
|
+
console.log(output);
|
|
34
|
+
process.exit(0);
|
|
35
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// must support array use
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express();
|
|
7
|
+
|
|
8
|
+
router.get('/asdf', (req, res) => {
|
|
9
|
+
res.send('asdf');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.use(['/abc', '/def'], router);
|
|
13
|
+
|
|
14
|
+
app.use((req, res, next) => {
|
|
15
|
+
res.send('404');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
console.log(router.mountpath); // should be last one
|
|
19
|
+
|
|
20
|
+
app.listen(13333, async () => {
|
|
21
|
+
console.log('Server is running on port 13333');
|
|
22
|
+
|
|
23
|
+
let res = await fetch('http://localhost:13333/abc/asdf');
|
|
24
|
+
console.log(await res.text());
|
|
25
|
+
|
|
26
|
+
res = await fetch('http://localhost:13333/def/asdf');
|
|
27
|
+
console.log(await res.text());
|
|
28
|
+
|
|
29
|
+
res = await fetch('http://localhost:13333/ghi/asdf');
|
|
30
|
+
console.log(await res.text());
|
|
31
|
+
|
|
32
|
+
process.exit(0);
|
|
33
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// must support async "use"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.use(async (req, res, next) => {
|
|
8
|
+
let start = Date.now();
|
|
9
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
10
|
+
res.took = Math.round((Date.now() - start) / 100) * 100;
|
|
11
|
+
next();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
app.get('/test', (req, res, next) => {
|
|
15
|
+
res.send(`took ${res.took}ms`);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.listen(13333, async () => {
|
|
19
|
+
console.log('Server is running on port 13333');
|
|
20
|
+
|
|
21
|
+
let output1 = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
22
|
+
|
|
23
|
+
console.log(output1);
|
|
24
|
+
process.exit(0);
|
|
25
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// must support complex routes
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/abc?d', (req, res) => {
|
|
8
|
+
res.send('1');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.get('/za*v', (req, res) => {
|
|
12
|
+
res.send('2');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.get('/g+t', (req, res) => {
|
|
16
|
+
res.send('3');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
app.get('/test(abc)?test', (req, res) => {
|
|
20
|
+
res.send('4');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.get('/*', (req, res) => {
|
|
24
|
+
res.send('5');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.listen(13333, async () => {
|
|
28
|
+
console.log('Server is running on port 13333');
|
|
29
|
+
|
|
30
|
+
let outputs = await Promise.all([
|
|
31
|
+
fetch('http://localhost:13333/abcd').then(res => res.text()),
|
|
32
|
+
fetch('http://localhost:13333/abd').then(res => res.text()),
|
|
33
|
+
fetch('http://localhost:13333/ad').then(res => res.text()),
|
|
34
|
+
|
|
35
|
+
fetch('http://localhost:13333/zav').then(res => res.text()),
|
|
36
|
+
fetch('http://localhost:13333/zaaaav').then(res => res.text()),
|
|
37
|
+
fetch('http://localhost:13333/zv').then(res => res.text()),
|
|
38
|
+
fetch('http://localhost:13333/zavv').then(res => res.text()),
|
|
39
|
+
|
|
40
|
+
fetch('http://localhost:13333/t').then(res => res.text()),
|
|
41
|
+
fetch('http://localhost:13333/gt').then(res => res.text()),
|
|
42
|
+
fetch('http://localhost:13333/ggggt').then(res => res.text()),
|
|
43
|
+
|
|
44
|
+
fetch('http://localhost:13333/testtest').then(res => res.text()),
|
|
45
|
+
fetch('http://localhost:13333/testabctest').then(res => res.text()),
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
console.log(outputs.join(' '));
|
|
49
|
+
process.exit(0);
|
|
50
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// must support a lot of param routes
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
for(let i = 0; i < 1000; i++) {
|
|
8
|
+
app.get(`/:test`, (req, res, next) => {
|
|
9
|
+
next();
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
app.get('/:test', (req, res) => {
|
|
14
|
+
res.send(req.params.test);
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
app.listen(13333, async () => {
|
|
19
|
+
console.log('Server is running on port 13333');
|
|
20
|
+
|
|
21
|
+
let res = await fetch('http://localhost:13333/asdf');
|
|
22
|
+
console.log(await res.text());
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
process.exit(0);
|
|
26
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// must support a lot of routes
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express.Router();
|
|
7
|
+
const router2 = express.Router();
|
|
8
|
+
|
|
9
|
+
for(let i = 0; i < 1000; i++) {
|
|
10
|
+
router.get(`/${i}`, (req, res) => {
|
|
11
|
+
res.send(i.toString());
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
app.use("/rou+ter", router);
|
|
16
|
+
|
|
17
|
+
for(let i = 0; i < 1000; i++) {
|
|
18
|
+
router2.get(`/${i}`, (req, res) => {
|
|
19
|
+
res.send(i.toString());
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
app.use("/b", router2);
|
|
24
|
+
|
|
25
|
+
for(let i = 0; i < 1000; i++) {
|
|
26
|
+
app.get(`/${i}`, (req, res) => {
|
|
27
|
+
res.send(i.toString());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for(let i = 0; i < 1000; i++) {
|
|
32
|
+
app.use((req, res, next) => {
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for(let i = 1000; i < 2000; i++) {
|
|
38
|
+
app.get(`/${i}`, (req, res) => {
|
|
39
|
+
res.send(i.toString());
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
app.listen(13333, async () => {
|
|
44
|
+
console.log('Server is running on port 13333');
|
|
45
|
+
|
|
46
|
+
let res = await fetch('http://localhost:13333/999');
|
|
47
|
+
console.log(await res.text());
|
|
48
|
+
|
|
49
|
+
res = await fetch('http://localhost:13333/1999');
|
|
50
|
+
console.log(await res.text());
|
|
51
|
+
|
|
52
|
+
res = await fetch('http://localhost:13333/rouuuter/999');
|
|
53
|
+
console.log(await res.text());
|
|
54
|
+
|
|
55
|
+
res = await fetch('http://localhost:13333/b/999');
|
|
56
|
+
console.log(await res.text());
|
|
57
|
+
|
|
58
|
+
process.exit(0);
|
|
59
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// must support existent next("route") (optimized)
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
app.set('env', 'production');
|
|
7
|
+
|
|
8
|
+
app.get('/test', (req, res, next) => {
|
|
9
|
+
console.log('1');
|
|
10
|
+
next("route");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.get('/test', (req, res) => {
|
|
14
|
+
console.log('2');
|
|
15
|
+
res.send('Hello World');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.get('/test', (req, res) => {
|
|
19
|
+
console.log('3');
|
|
20
|
+
res.send('Hello World');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.listen(13333, async () => {
|
|
24
|
+
console.log('Server is running on port 13333');
|
|
25
|
+
|
|
26
|
+
const response = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
27
|
+
console.log(response);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// must support existent next("route")
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
app.set('env', 'production');
|
|
7
|
+
|
|
8
|
+
app.get('/te*st', (req, res, next) => {
|
|
9
|
+
console.log('1');
|
|
10
|
+
next("route");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.get('/te*st', (req, res) => {
|
|
14
|
+
console.log('2');
|
|
15
|
+
res.send('Hello World');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.get('/te*st', (req, res) => {
|
|
19
|
+
console.log('3');
|
|
20
|
+
res.send('Hello World');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.listen(13333, async () => {
|
|
24
|
+
console.log('Server is running on port 13333');
|
|
25
|
+
|
|
26
|
+
const response = await fetch('http://localhost:13333/teest').then(res => res.text());
|
|
27
|
+
console.log(response);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// must support non-existent next("route") (optimized)
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
app.set('env', 'production');
|
|
7
|
+
|
|
8
|
+
app.get('/test', (req, res, next) => {
|
|
9
|
+
console.log('1');
|
|
10
|
+
next("route");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.listen(13333, async () => {
|
|
14
|
+
console.log('Server is running on port 13333');
|
|
15
|
+
|
|
16
|
+
const response = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
17
|
+
console.log(response);
|
|
18
|
+
process.exit(0);
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// must support non-existent next("route")
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
app.set('env', 'production');
|
|
7
|
+
|
|
8
|
+
app.get('te*st', (req, res, next) => {
|
|
9
|
+
console.log('1');
|
|
10
|
+
next("route");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.listen(13333, async () => {
|
|
14
|
+
console.log('Server is running on port 13333');
|
|
15
|
+
|
|
16
|
+
const response = await fetch('http://localhost:13333/teest').then(res => res.text());
|
|
17
|
+
console.log(response);
|
|
18
|
+
process.exit(0);
|
|
19
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// special cases for next()
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
app.set('env', 'production');
|
|
7
|
+
|
|
8
|
+
app.get('/test', (req, res, next) => {
|
|
9
|
+
console.log('first');
|
|
10
|
+
next();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.get('/test', (req, res, next) => {
|
|
14
|
+
console.log('second');
|
|
15
|
+
next('route');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.get('/test', (req, res, next) => {
|
|
19
|
+
console.log('third');
|
|
20
|
+
next('route');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.get('/test', (req, res, next) => {
|
|
24
|
+
console.log('fourth');
|
|
25
|
+
next('route');
|
|
26
|
+
}, (req, res, next) => {
|
|
27
|
+
console.log('fifth');
|
|
28
|
+
next();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
app.get('/test', (req, res, next) => {
|
|
32
|
+
console.log('sixth');
|
|
33
|
+
res.send('done');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
app.get('/error', (req, res, next) => {
|
|
37
|
+
next(new Error('test error'));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
app.use((err, req, res, next) => {
|
|
41
|
+
console.log(err.message);
|
|
42
|
+
res.send('error');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
app.listen(13333, async () => {
|
|
47
|
+
console.log('Server is running on port 13333');
|
|
48
|
+
|
|
49
|
+
const response = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
50
|
+
console.log(response);
|
|
51
|
+
const response2 = await fetch('http://localhost:13333/error').then(res => res.text());
|
|
52
|
+
console.log(response2);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// must support unoptimized after optimized
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
app.set('env', 'production');
|
|
7
|
+
|
|
8
|
+
app.get('/test',
|
|
9
|
+
(req, res, next) => {
|
|
10
|
+
console.log('1');
|
|
11
|
+
next();
|
|
12
|
+
},
|
|
13
|
+
(req, res, next) => {
|
|
14
|
+
console.log('2');
|
|
15
|
+
next('route');
|
|
16
|
+
},
|
|
17
|
+
(req, res, next) => {
|
|
18
|
+
console.log('3');
|
|
19
|
+
next();
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
app.get('/test', (req, res, next) => {
|
|
24
|
+
console.log('4');
|
|
25
|
+
next();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
app.get('/:test', (req, res) => {
|
|
29
|
+
console.log('5');
|
|
30
|
+
res.send('Hello World');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
app.listen(13333, async () => {
|
|
34
|
+
console.log('Server is running on port 13333');
|
|
35
|
+
|
|
36
|
+
const response = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
37
|
+
console.log(response);
|
|
38
|
+
process.exit(0);
|
|
39
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// must support use without path
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.use(async (req, res, next) => {
|
|
8
|
+
console.log('use');
|
|
9
|
+
next();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.get('/test', (req, res, next) => {
|
|
13
|
+
res.send('test');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.get('/test/test', (req, res, next) => {
|
|
17
|
+
res.send('test/test');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.listen(13333, async () => {
|
|
21
|
+
console.log('Server is running on port 13333');
|
|
22
|
+
|
|
23
|
+
let output1 = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
24
|
+
let output2 = await fetch('http://localhost:13333/test/test').then(res => res.text());
|
|
25
|
+
|
|
26
|
+
console.log(output1);
|
|
27
|
+
console.log(output2);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// must support array and regex routes
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get(['/a', '/b'], (req, res) => {
|
|
8
|
+
res.send('1');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.get(/^\/c|\/d$/, (req, res) => {
|
|
12
|
+
res.send('2');
|
|
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/a').then(res => res.text()),
|
|
20
|
+
fetch('http://localhost:13333/b').then(res => res.text()),
|
|
21
|
+
fetch('http://localhost:13333/c').then(res => res.text()),
|
|
22
|
+
fetch('http://localhost:13333/d').then(res => res.text()),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
console.log(outputs.join(' '));
|
|
26
|
+
process.exit(0);
|
|
27
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// must support multiple mountpaths
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
const router = express();
|
|
7
|
+
|
|
8
|
+
router.get('/asdf', (req, res) => {
|
|
9
|
+
res.send('asdf');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.use('/abc', router);
|
|
13
|
+
app.use('/def', router);
|
|
14
|
+
|
|
15
|
+
app.use((req, res, next) => {
|
|
16
|
+
res.send('404');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
console.log(router.mountpath); // should be last one
|
|
20
|
+
|
|
21
|
+
app.listen(13333, async () => {
|
|
22
|
+
console.log('Server is running on port 13333');
|
|
23
|
+
|
|
24
|
+
let res = await fetch('http://localhost:13333/abc/asdf');
|
|
25
|
+
console.log(await res.text());
|
|
26
|
+
|
|
27
|
+
res = await fetch('http://localhost:13333/def/asdf');
|
|
28
|
+
console.log(await res.text());
|
|
29
|
+
|
|
30
|
+
res = await fetch('http://localhost:13333/ghi/asdf');
|
|
31
|
+
console.log(await res.text());
|
|
32
|
+
|
|
33
|
+
process.exit(0);
|
|
34
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// must support simple routes
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.get('/', (req, res) => {
|
|
8
|
+
res.send('Hello World');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
app.get('/test', (req, res) => {
|
|
12
|
+
res.send('test');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
app.get('/test/testy', (req, res) => {
|
|
16
|
+
res.send('testy');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
app.listen(13333, async () => {
|
|
20
|
+
console.log('Server is running on port 13333');
|
|
21
|
+
|
|
22
|
+
let r1 = await fetch('http://localhost:13333/').then(res => res.text());
|
|
23
|
+
let r2 = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
24
|
+
let r3 = await fetch('http://localhost:13333/testy').then(res => res.text());
|
|
25
|
+
let r4 = await fetch('http://localhost:13333/test/testy').then(res => res.text());
|
|
26
|
+
|
|
27
|
+
console.log(r1, r2, r3, r4);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// must support simple "use"
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
app.use((req, res, next) => {
|
|
8
|
+
console.log('u1');
|
|
9
|
+
next();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.use('/', (req, res, next) => {
|
|
13
|
+
console.log('u2');
|
|
14
|
+
next();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
app.use('/tes', (req, res, next) => {
|
|
18
|
+
console.log('u3');
|
|
19
|
+
next();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app.use('/test', (req, res, next) => {
|
|
23
|
+
console.log('u4');
|
|
24
|
+
next();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.get('/test', (req, res) => {
|
|
28
|
+
res.send('test');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
app.use('/asdf', (req, res, next) => {
|
|
32
|
+
console.log('u5');
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
app.get('/asdf/asdf', (req, res) => {
|
|
37
|
+
res.send('asdf');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
app.use((req, res, next) => {
|
|
41
|
+
console.log('404')
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
app.listen(13333, async () => {
|
|
45
|
+
console.log('Server is running on port 13333');
|
|
46
|
+
|
|
47
|
+
let output1 = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
48
|
+
let output2 = await fetch('http://localhost:13333/asdf/asdf').then(res => res.text());
|
|
49
|
+
|
|
50
|
+
console.log(output1, output2);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// must support 10 nested middlewares
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
let middleware = (req, res, next) => {
|
|
7
|
+
next();
|
|
8
|
+
};
|
|
9
|
+
let middlewares = [];
|
|
10
|
+
for(let i = 0; i < 10; i++) {
|
|
11
|
+
middlewares.push(middleware);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
for(let i = 0; i < 100; i++) {
|
|
15
|
+
app.get(`/${i}`, ...middlewares, (req, res) => {
|
|
16
|
+
res.send(i.toString());
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
app.listen(13333, async () => {
|
|
22
|
+
console.log('Server is running on port 13333');
|
|
23
|
+
|
|
24
|
+
let res = await fetch('http://localhost:13333/90');
|
|
25
|
+
console.log(await res.text());
|
|
26
|
+
process.exit(0);
|
|
27
|
+
})
|