ultimate-express 1.0.0 → 1.0.2
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/LICENSE +13 -0
- package/README.md +2 -1
- package/package.json +8 -4
- package/.github/workflows/test.yml +0 -27
- package/tests/index.js +0 -64
- package/tests/parts/.test/index.html +0 -11
- package/tests/parts/big.jpg +0 -0
- package/tests/parts/index.art +0 -12
- package/tests/parts/index.dot +0 -12
- package/tests/parts/index.ejs +0 -12
- package/tests/parts/index.handlebars +0 -2
- package/tests/parts/index.html +0 -12
- package/tests/parts/index.mustache +0 -12
- package/tests/parts/index.pug +0 -6
- package/tests/parts/index.swig +0 -12
- package/tests/parts/layouts/main.handlebars +0 -12
- package/tests/preload.cjs +0 -5
- package/tests/singular.js +0 -41
- package/tests/tests/app/app-engine.js +0 -8
- package/tests/tests/app/app-on-mount.js +0 -24
- package/tests/tests/app/app-path.js +0 -21
- package/tests/tests/app/app-route.js +0 -30
- package/tests/tests/app/options.js +0 -16
- package/tests/tests/app/setting-inheritance.js +0 -16
- package/tests/tests/engines/art-template.js +0 -33
- package/tests/tests/engines/dot.js +0 -28
- package/tests/tests/engines/ejs.js +0 -25
- package/tests/tests/engines/handlebars.js +0 -28
- package/tests/tests/engines/mustache.js +0 -28
- package/tests/tests/engines/pug.js +0 -25
- package/tests/tests/engines/swig.js +0 -28
- package/tests/tests/errors/error-handling-middleware.js +0 -22
- package/tests/tests/errors/next-error-optimized.js +0 -26
- package/tests/tests/errors/next-error.js +0 -26
- package/tests/tests/errors/unexpected-error-handling.js +0 -18
- package/tests/tests/listen/listen-random.js +0 -11
- package/tests/tests/listen/listen-specific.js +0 -17
- package/tests/tests/middlewares/body-json.js +0 -31
- package/tests/tests/middlewares/body-raw-deflate.js +0 -43
- package/tests/tests/middlewares/body-raw-gzip.js +0 -43
- package/tests/tests/middlewares/body-raw.js +0 -41
- package/tests/tests/middlewares/body-text.js +0 -27
- package/tests/tests/middlewares/body-urlencoded.js +0 -30
- package/tests/tests/middlewares/cookie-parser-signed.js +0 -31
- package/tests/tests/middlewares/cookie-parser.js +0 -28
- package/tests/tests/middlewares/cookie-session.js +0 -40
- package/tests/tests/middlewares/cors.js +0 -29
- package/tests/tests/middlewares/errorhandler.js +0 -26
- package/tests/tests/middlewares/express-fileupload-temp.js +0 -46
- package/tests/tests/middlewares/express-fileupload.js +0 -28
- package/tests/tests/middlewares/express-rate-limit.js +0 -33
- package/tests/tests/middlewares/express-session.js +0 -37
- package/tests/tests/middlewares/express-static-options.js +0 -72
- package/tests/tests/middlewares/express-static.js +0 -40
- package/tests/tests/middlewares/method-override.js +0 -33
- package/tests/tests/middlewares/multer.js +0 -43
- package/tests/tests/middlewares/multiple-middlewares.js +0 -37
- package/tests/tests/middlewares/response-time.js +0 -29
- package/tests/tests/middlewares/serve-index.js +0 -38
- package/tests/tests/middlewares/serve-static.js +0 -38
- package/tests/tests/middlewares/vhost.js +0 -50
- package/tests/tests/params/array-param.js +0 -30
- package/tests/tests/params/nested-params.js +0 -24
- package/tests/tests/params/param-errors.js +0 -56
- package/tests/tests/params/param-function.js +0 -49
- package/tests/tests/params/param-next-route.js +0 -48
- package/tests/tests/params/param-optimized.js +0 -38
- package/tests/tests/params/param-use.js +0 -39
- package/tests/tests/params/param.js +0 -68
- package/tests/tests/params/params-regex.js +0 -26
- package/tests/tests/params/params-use.js +0 -20
- package/tests/tests/params/params.js +0 -35
- package/tests/tests/req/req-accepts-charsets.js +0 -40
- package/tests/tests/req/req-accepts-encodings.js +0 -36
- package/tests/tests/req/req-accepts-languages.js +0 -41
- package/tests/tests/req/req-accepts.js +0 -41
- package/tests/tests/req/req-app.js +0 -17
- package/tests/tests/req/req-baseurl.js +0 -38
- package/tests/tests/req/req-connection.js +0 -19
- package/tests/tests/req/req-fresh.js +0 -59
- package/tests/tests/req/req-get.js +0 -78
- package/tests/tests/req/req-headers-distinct.js +0 -72
- package/tests/tests/req/req-headers.js +0 -72
- package/tests/tests/req/req-host.js +0 -45
- package/tests/tests/req/req-hostname.js +0 -45
- package/tests/tests/req/req-ip.js +0 -19
- package/tests/tests/req/req-is.js +0 -44
- package/tests/tests/req/req-original-url.js +0 -29
- package/tests/tests/req/req-param.js +0 -29
- package/tests/tests/req/req-protocol.js +0 -20
- package/tests/tests/req/req-query.js +0 -23
- package/tests/tests/req/req-range.js +0 -48
- package/tests/tests/req/req-raw-headers.js +0 -72
- package/tests/tests/req/req-subdomains.js +0 -48
- package/tests/tests/req/req-url-nested.js +0 -27
- package/tests/tests/req/req-url-optimized-router.js +0 -26
- package/tests/tests/req/req-url-optimized.js +0 -23
- package/tests/tests/req/req-url.js +0 -36
- package/tests/tests/req/req-xhr.js +0 -23
- package/tests/tests/res/head-content-length.js +0 -18
- package/tests/tests/res/head.js +0 -47
- package/tests/tests/res/injecting.js +0 -25
- package/tests/tests/res/piping.js +0 -23
- package/tests/tests/res/res-app.js +0 -17
- package/tests/tests/res/res-append.js +0 -24
- package/tests/tests/res/res-attachment.js +0 -19
- package/tests/tests/res/res-clear-cookie.js +0 -18
- package/tests/tests/res/res-cookie.js +0 -22
- package/tests/tests/res/res-download.js +0 -36
- package/tests/tests/res/res-format.js +0 -57
- package/tests/tests/res/res-get.js +0 -18
- package/tests/tests/res/res-headers-sent.js +0 -18
- package/tests/tests/res/res-json.js +0 -17
- package/tests/tests/res/res-jsonp.js +0 -25
- package/tests/tests/res/res-links.js +0 -21
- package/tests/tests/res/res-location.js +0 -34
- package/tests/tests/res/res-redirect.js +0 -46
- package/tests/tests/res/res-remove-header.js +0 -19
- package/tests/tests/res/res-send-file.js +0 -17
- package/tests/tests/res/res-send-status.js +0 -17
- package/tests/tests/res/res-send.js +0 -69
- package/tests/tests/res/res-set.js +0 -28
- package/tests/tests/res/res-status.js +0 -18
- package/tests/tests/res/res-type.js +0 -19
- package/tests/tests/res/res-vary.js +0 -19
- package/tests/tests/res/res-write.js +0 -29
- package/tests/tests/routers/complex-routers.js +0 -34
- package/tests/tests/routers/empty-router.js +0 -25
- package/tests/tests/routers/lot-of-routes.js +0 -38
- package/tests/tests/routers/mergeparams.js +0 -42
- package/tests/tests/routers/nested-routers.js +0 -52
- package/tests/tests/routers/router-options.js +0 -68
- package/tests/tests/routers/routers.js +0 -45
- package/tests/tests/routers/simple-routers.js +0 -35
- package/tests/tests/routing/all.js +0 -47
- package/tests/tests/routing/array-arguments.js +0 -35
- package/tests/tests/routing/array-use.js +0 -33
- package/tests/tests/routing/async-use.js +0 -25
- package/tests/tests/routing/complex-routes.js +0 -50
- package/tests/tests/routing/lot-of-param-routes.js +0 -26
- package/tests/tests/routing/lot-of-routes.js +0 -59
- package/tests/tests/routing/next-existent-optimized-route.js +0 -29
- package/tests/tests/routing/next-existent-route.js +0 -29
- package/tests/tests/routing/next-nonexistent-optimized-route.js +0 -19
- package/tests/tests/routing/next-nonexistent-route.js +0 -19
- package/tests/tests/routing/next-special-cases.js +0 -54
- package/tests/tests/routing/next-unoptimized.js +0 -39
- package/tests/tests/routing/no-path-use.js +0 -29
- package/tests/tests/routing/non-string-routes.js +0 -27
- package/tests/tests/routing/req-multiple-mountpaths.js +0 -34
- package/tests/tests/routing/simple-routes.js +0 -29
- package/tests/tests/routing/simple-use.js +0 -52
- package/tests/tests/routing/some-middlewares.js +0 -27
- package/tests/tests/routing/special-characters.js +0 -28
- package/tests/tests/routing/star.js +0 -31
- package/tests/tests/routing/sub-apps.js +0 -32
- package/tests/tests/routing/trailing-slash.js +0 -37
- package/tests/tests/routing/weird-route-start.js +0 -18
- package/tests/tests/send-file/accept-ranges.js +0 -26
- package/tests/tests/send-file/callback.js +0 -23
- package/tests/tests/send-file/default-error-routing.js +0 -21
- package/tests/tests/send-file/dotfiles.js +0 -24
- package/tests/tests/send-file/etag.js +0 -19
- package/tests/tests/send-file/fs-threads.js +0 -39
- package/tests/tests/send-file/head.js +0 -49
- package/tests/tests/send-file/headers.js +0 -23
- package/tests/tests/send-file/if-match.js +0 -31
- package/tests/tests/send-file/if-range.js +0 -37
- package/tests/tests/send-file/if-unmodified-since.js +0 -32
- package/tests/tests/send-file/immutable.js +0 -22
- package/tests/tests/send-file/large-file.js +0 -19
- package/tests/tests/send-file/last-modified.js +0 -21
- package/tests/tests/send-file/max-age.js +0 -21
- package/tests/tests/send-file/path-traversal.js +0 -35
- package/tests/tests/send-file/range.js +0 -57
- package/tests/tests/send-file/simple.js +0 -18
- package/tests/tests/settings/case-sensitive-routing.js +0 -48
- package/tests/tests/settings/env-errors.js +0 -38
- package/tests/tests/settings/etag.js +0 -36
- package/tests/tests/settings/json-escape.js +0 -45
- package/tests/tests/settings/json-replacer.js +0 -50
- package/tests/tests/settings/json-spaces.js +0 -44
- package/tests/tests/settings/query-parser.js +0 -45
- package/tests/tests/settings/strict-routing.js +0 -64
- package/tests/tests/settings/subdomain-offset.js +0 -38
- package/tests/tests/settings/trust-proxy-host.js +0 -58
- package/tests/tests/settings/trust-proxy-ip.js +0 -58
- package/tests/tests/settings/trust-proxy-ips.js +0 -58
- package/tests/tests/settings/trust-proxy-protocol.js +0 -46
- package/tests/tests/settings/x-powered-by.js +0 -32
- package/tests/uws.js +0 -14
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// error handling middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
|
|
5
|
-
const app = express();
|
|
6
|
-
app.set('env', 'production');
|
|
7
|
-
|
|
8
|
-
app.get('/test', (req, res) => {
|
|
9
|
-
throw new Error('test');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
app.use((err, req, res, next) => {
|
|
13
|
-
res.status(500).send(`whoops!`);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
app.listen(13333, async () => {
|
|
17
|
-
console.log('Server is running on port 13333');
|
|
18
|
-
|
|
19
|
-
const response = await fetch('http://localhost:13333/test').then(res => res.text());
|
|
20
|
-
console.log(response);
|
|
21
|
-
process.exit(0);
|
|
22
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// support optimized next(err)
|
|
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
|
-
next(new Error('test'));
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
app.get('/test', (req, res, next) => {
|
|
13
|
-
res.send('test');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
app.use((err, req, res, next) => {
|
|
17
|
-
res.status(500).send(`whoops!`);
|
|
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/test').then(res => res.text());
|
|
24
|
-
console.log(response);
|
|
25
|
-
process.exit(0);
|
|
26
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// support next(err)
|
|
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
|
-
next(new Error('test'));
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
app.get('/:test', (req, res, next) => {
|
|
13
|
-
res.send('test');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
app.use((err, req, res, next) => {
|
|
17
|
-
res.status(500).send(`whoops!`);
|
|
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/test').then(res => res.text());
|
|
24
|
-
console.log(response);
|
|
25
|
-
process.exit(0);
|
|
26
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// unexpected error handling
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
|
|
5
|
-
const app = express();
|
|
6
|
-
app.set('env', 'production');
|
|
7
|
-
|
|
8
|
-
app.get('/test', (req, res) => {
|
|
9
|
-
throw new Error('Ignore this error, its used in a 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
|
-
console.log(response);
|
|
17
|
-
process.exit(0);
|
|
18
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// must open specified port
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
|
|
5
|
-
const app = express();
|
|
6
|
-
|
|
7
|
-
app.listen(13333, () => {
|
|
8
|
-
console.log('Server is running on port 13333');
|
|
9
|
-
|
|
10
|
-
fetch('http://localhost:13333').then(res => res.text()).then(body => {
|
|
11
|
-
console.log(body);
|
|
12
|
-
process.exit(0);
|
|
13
|
-
}).catch(err => {
|
|
14
|
-
console.error(err);
|
|
15
|
-
process.exit(1);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// must support json body parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(bodyParser.json());
|
|
9
|
-
|
|
10
|
-
app.post('/abc', (req, res) => {
|
|
11
|
-
res.send(req.body);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
app.listen(13333, async () => {
|
|
15
|
-
console.log('Server is running on port 13333');
|
|
16
|
-
|
|
17
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
abc: 123
|
|
21
|
-
}),
|
|
22
|
-
headers: {
|
|
23
|
-
'Content-Type': 'application/json'
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
const text = await response.text();
|
|
27
|
-
console.log(text);
|
|
28
|
-
|
|
29
|
-
process.exit(0);
|
|
30
|
-
|
|
31
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// must support deflate raw body parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
const { deflate } = require("pako");
|
|
6
|
-
|
|
7
|
-
const app = express();
|
|
8
|
-
|
|
9
|
-
app.use(bodyParser.raw());
|
|
10
|
-
|
|
11
|
-
app.post('/abc', (req, res) => {
|
|
12
|
-
res.send(req.body);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
app.listen(13333, async () => {
|
|
16
|
-
console.log('Server is running on port 13333');
|
|
17
|
-
const ab = new ArrayBuffer(10);
|
|
18
|
-
const u8 = new Uint8Array(ab);
|
|
19
|
-
u8[0] = 1;
|
|
20
|
-
u8[1] = 2;
|
|
21
|
-
u8[2] = 3;
|
|
22
|
-
u8[3] = 4;
|
|
23
|
-
u8[4] = 5;
|
|
24
|
-
u8[5] = 6;
|
|
25
|
-
u8[6] = 7;
|
|
26
|
-
u8[7] = 8;
|
|
27
|
-
u8[8] = 9;
|
|
28
|
-
|
|
29
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
body: await deflate(ab),
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/octet-stream',
|
|
34
|
-
'Content-Encoding': 'deflate'
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const text = await response.text();
|
|
39
|
-
console.log(text);
|
|
40
|
-
|
|
41
|
-
process.exit(0);
|
|
42
|
-
|
|
43
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// must support gzipped raw body parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
const { gzip } = require("pako");
|
|
6
|
-
|
|
7
|
-
const app = express();
|
|
8
|
-
|
|
9
|
-
app.use(bodyParser.raw());
|
|
10
|
-
|
|
11
|
-
app.post('/abc', (req, res) => {
|
|
12
|
-
res.send(req.body);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
app.listen(13333, async () => {
|
|
16
|
-
console.log('Server is running on port 13333');
|
|
17
|
-
const ab = new ArrayBuffer(10);
|
|
18
|
-
const u8 = new Uint8Array(ab);
|
|
19
|
-
u8[0] = 1;
|
|
20
|
-
u8[1] = 2;
|
|
21
|
-
u8[2] = 3;
|
|
22
|
-
u8[3] = 4;
|
|
23
|
-
u8[4] = 5;
|
|
24
|
-
u8[5] = 6;
|
|
25
|
-
u8[6] = 7;
|
|
26
|
-
u8[7] = 8;
|
|
27
|
-
u8[8] = 9;
|
|
28
|
-
|
|
29
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
body: await gzip(ab),
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/octet-stream',
|
|
34
|
-
'Content-Encoding': 'gzip'
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const text = await response.text();
|
|
39
|
-
console.log(text);
|
|
40
|
-
|
|
41
|
-
process.exit(0);
|
|
42
|
-
|
|
43
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// must support raw body parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(bodyParser.raw());
|
|
9
|
-
|
|
10
|
-
app.post('/abc', (req, res) => {
|
|
11
|
-
res.send(req.body);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
app.listen(13333, async () => {
|
|
15
|
-
console.log('Server is running on port 13333');
|
|
16
|
-
const ab = new ArrayBuffer(10);
|
|
17
|
-
const u8 = new Uint8Array(ab);
|
|
18
|
-
u8[0] = 1;
|
|
19
|
-
u8[1] = 2;
|
|
20
|
-
u8[2] = 3;
|
|
21
|
-
u8[3] = 4;
|
|
22
|
-
u8[4] = 5;
|
|
23
|
-
u8[5] = 6;
|
|
24
|
-
u8[6] = 7;
|
|
25
|
-
u8[7] = 8;
|
|
26
|
-
u8[8] = 9;
|
|
27
|
-
|
|
28
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
body: ab,
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/octet-stream'
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const text = await response.text();
|
|
37
|
-
console.log(text);
|
|
38
|
-
|
|
39
|
-
process.exit(0);
|
|
40
|
-
|
|
41
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// must support text body parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(bodyParser.text());
|
|
9
|
-
|
|
10
|
-
app.post('/abc', (req, res) => {
|
|
11
|
-
res.send(req.body);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
app.listen(13333, async () => {
|
|
15
|
-
console.log('Server is running on port 13333');
|
|
16
|
-
|
|
17
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
body: 'abc',
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const text = await response.text();
|
|
23
|
-
console.log(text);
|
|
24
|
-
|
|
25
|
-
process.exit(0);
|
|
26
|
-
|
|
27
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// must support urlencoded body parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(bodyParser.urlencoded({ extended: false }));
|
|
9
|
-
|
|
10
|
-
app.post('/abc', (req, res) => {
|
|
11
|
-
res.send(req.body);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
app.listen(13333, async () => {
|
|
15
|
-
console.log('Server is running on port 13333');
|
|
16
|
-
|
|
17
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
body: 'abc=123',
|
|
20
|
-
headers: {
|
|
21
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const text = await response.text();
|
|
26
|
-
console.log(text);
|
|
27
|
-
|
|
28
|
-
process.exit(0);
|
|
29
|
-
|
|
30
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// must support cookie parser with signed cookies
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const cookieParser = require("cookie-parser");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(cookieParser('secret'));
|
|
9
|
-
|
|
10
|
-
app.get('/abc', (req, res) => {
|
|
11
|
-
res.cookie('abc', '123', { signed: true });
|
|
12
|
-
res.send('ok');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
app.get('/def', (req, res) => {
|
|
16
|
-
console.log(req.signedCookies, req.headers.cookie);
|
|
17
|
-
res.send('ok');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
app.listen(13333, async () => {
|
|
21
|
-
console.log('Server is running on port 13333');
|
|
22
|
-
|
|
23
|
-
const cookie = await fetch('http://localhost:13333/abc').then(res => res.headers.get('Set-Cookie'));
|
|
24
|
-
console.log(cookie);
|
|
25
|
-
await fetch('http://localhost:13333/def', {
|
|
26
|
-
headers: {
|
|
27
|
-
'Cookie': cookie.split('; ')[0]
|
|
28
|
-
}
|
|
29
|
-
}).then(res => res.text());
|
|
30
|
-
process.exit(0);
|
|
31
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// must support cookie parser
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const cookieParser = require("cookie-parser");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(cookieParser());
|
|
9
|
-
|
|
10
|
-
app.get('/abc', (req, res) => {
|
|
11
|
-
console.log(req.cookies);
|
|
12
|
-
res.send('ok');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
app.listen(13333, async () => {
|
|
16
|
-
console.log('Server is running on port 13333');
|
|
17
|
-
|
|
18
|
-
await Promise.all([
|
|
19
|
-
fetch('http://localhost:13333/abc', {
|
|
20
|
-
headers: {
|
|
21
|
-
'Cookie': 'abc=123; def=456'
|
|
22
|
-
}
|
|
23
|
-
}).then(res => res.text())
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
process.exit(0);
|
|
27
|
-
|
|
28
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// must support cookie-session middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const cookieSession = require('cookie-session');
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(cookieSession({
|
|
9
|
-
name: 'session',
|
|
10
|
-
keys: ["test"],
|
|
11
|
-
|
|
12
|
-
// Cookie Options
|
|
13
|
-
maxAge: 24 * 60 * 60 * 1000 // 24 hours
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
app.get('/abc', (req, res) => {
|
|
17
|
-
req.session.views = (req.session.views || 0) + 1;
|
|
18
|
-
res.status(202).send(`Viewed ${req.session.views} times.`);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
app.listen(13333, async () => {
|
|
22
|
-
console.log('Server is running on port 13333');
|
|
23
|
-
|
|
24
|
-
const response = await fetch('http://localhost:13333/abc');
|
|
25
|
-
const sessionCookie = response.headers.get('Set-Cookie').match(/session=(.*?);/)[1];
|
|
26
|
-
const sessionSig = response.headers.get('Set-Cookie').match(/session.sig=(.*?);/)[1];
|
|
27
|
-
const text = await response.text();
|
|
28
|
-
console.log(text, sessionCookie, sessionSig, response.status);
|
|
29
|
-
|
|
30
|
-
const response2 = await fetch('http://localhost:13333/abc', {
|
|
31
|
-
headers: {
|
|
32
|
-
'Cookie': `session=${sessionCookie}; session.sig=${sessionSig}`
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const text2 = await response2.text();
|
|
36
|
-
console.log(text2);
|
|
37
|
-
|
|
38
|
-
process.exit(0);
|
|
39
|
-
|
|
40
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// must support cors middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const cors = require("cors");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.get('/abc', cors(), (req, res) => {
|
|
9
|
-
res.send('1');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
app.get('/def', cors({
|
|
13
|
-
origin: 'http://example.com',
|
|
14
|
-
}), (req, res) => {
|
|
15
|
-
res.send('2');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
app.listen(13333, async () => {
|
|
19
|
-
console.log('Server is running on port 13333');
|
|
20
|
-
|
|
21
|
-
const response = await fetch('http://localhost:13333/abc');
|
|
22
|
-
console.log(response.headers.get('access-control-allow-origin'));
|
|
23
|
-
|
|
24
|
-
const response2 = await fetch('http://localhost:13333/def');
|
|
25
|
-
console.log(response2.headers.get('access-control-allow-origin'));
|
|
26
|
-
|
|
27
|
-
process.exit(0);
|
|
28
|
-
|
|
29
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// must support errorhandler middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const errorhandler = require('errorhandler')
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.get('/abc', (req, res) => {
|
|
9
|
-
throw new Error('test');
|
|
10
|
-
res.send(req.body);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
app.use(errorhandler({
|
|
14
|
-
log: (err) => {
|
|
15
|
-
console.log(`hi`, err.message);
|
|
16
|
-
}
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
app.listen(13333, async () => {
|
|
20
|
-
console.log('Server is running on port 13333');
|
|
21
|
-
|
|
22
|
-
const response = await fetch('http://localhost:13333/abc');
|
|
23
|
-
|
|
24
|
-
process.exit(0);
|
|
25
|
-
|
|
26
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// must support express-fileupload middleware with temp file
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const fileUpload = require("express-fileupload");
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
|
|
7
|
-
const app = express();
|
|
8
|
-
|
|
9
|
-
app.post('/file', fileUpload({
|
|
10
|
-
tempFileDir: './tmp',
|
|
11
|
-
useTempFiles: true,
|
|
12
|
-
debug: false
|
|
13
|
-
}), (req, res) => {
|
|
14
|
-
req.files.file.mv('./tmp/test.txt');
|
|
15
|
-
res.send(req.files.file.size.toString());
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
app.listen(13333, async () => {
|
|
19
|
-
console.log('Server is running on port 13333');
|
|
20
|
-
|
|
21
|
-
const formData = new FormData();
|
|
22
|
-
console.log('creating file');
|
|
23
|
-
const arr = new Uint8Array(1024 * 256); // 256 KB
|
|
24
|
-
console.log('filling file');
|
|
25
|
-
for (let i = 0; i < arr.length; i++) {
|
|
26
|
-
arr[i] = i % 256;
|
|
27
|
-
}
|
|
28
|
-
console.log('appending file');
|
|
29
|
-
const file = new File(arr, 'test.txt');
|
|
30
|
-
formData.append('file', file);
|
|
31
|
-
|
|
32
|
-
console.log('sending request');
|
|
33
|
-
const response = await fetch('http://localhost:13333/file', {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
body: formData
|
|
36
|
-
});
|
|
37
|
-
console.log('response', response.status);
|
|
38
|
-
const text = await response.text();
|
|
39
|
-
console.log(text);
|
|
40
|
-
|
|
41
|
-
console.log('temp file', fs.statSync('./tmp/test.txt').size);
|
|
42
|
-
fs.rmSync('./tmp', { recursive: true, force: true });
|
|
43
|
-
|
|
44
|
-
process.exit(0);
|
|
45
|
-
|
|
46
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// must support express-fileupload middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const fileUpload = require("express-fileupload");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.post('/file', fileUpload(), (req, res) => {
|
|
9
|
-
res.send(req.files);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
app.listen(13333, async () => {
|
|
13
|
-
console.log('Server is running on port 13333');
|
|
14
|
-
|
|
15
|
-
const formData = new FormData();
|
|
16
|
-
const file = new File([1, 2, 3], 'test.txt');
|
|
17
|
-
formData.append('file', file);
|
|
18
|
-
|
|
19
|
-
const response = await fetch('http://localhost:13333/file', {
|
|
20
|
-
method: 'POST',
|
|
21
|
-
body: formData
|
|
22
|
-
});
|
|
23
|
-
const text = await response.text();
|
|
24
|
-
console.log(text);
|
|
25
|
-
|
|
26
|
-
process.exit(0);
|
|
27
|
-
|
|
28
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// must support express-rate-limit middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const { rateLimit } = require('express-rate-limit');
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(rateLimit({
|
|
9
|
-
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
10
|
-
limit: 1,
|
|
11
|
-
legacyHeaders: true,
|
|
12
|
-
handler: (req, res, next) => {
|
|
13
|
-
console.log('Too Many Requests called');
|
|
14
|
-
res.status(429).send('Too Many Requests');
|
|
15
|
-
}
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
app.get('/abc', (req, res) => {
|
|
19
|
-
res.send('Hello World');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
app.listen(13333, async () => {
|
|
23
|
-
console.log('Server is running on port 13333');
|
|
24
|
-
|
|
25
|
-
const response = await fetch('http://localhost:13333/abc');
|
|
26
|
-
console.log(await response.text());
|
|
27
|
-
|
|
28
|
-
const response2 = await fetch('http://localhost:13333/abc');
|
|
29
|
-
console.log(await response2.text(), response2.headers.get('X-RateLimit-Limit'), response2.headers.get('X-RateLimit-Remaining'));
|
|
30
|
-
|
|
31
|
-
process.exit(0);
|
|
32
|
-
|
|
33
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// must support express-session middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const session = require('express-session');
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(session({
|
|
9
|
-
secret: 'keyboard cat',
|
|
10
|
-
resave: false,
|
|
11
|
-
saveUninitialized: true
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
app.get('/abc', (req, res) => {
|
|
15
|
-
req.session.views = (req.session.views || 0) + 1;
|
|
16
|
-
res.status(202).send(`Viewed ${req.session.views} times.`);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
app.listen(13333, async () => {
|
|
20
|
-
console.log('Server is running on port 13333');
|
|
21
|
-
|
|
22
|
-
const response = await fetch('http://localhost:13333/abc');
|
|
23
|
-
const cookie = response.headers.get('Set-Cookie').match(/connect.sid=(.*?);/)[1];
|
|
24
|
-
const text = await response.text();
|
|
25
|
-
console.log(text, response.status);
|
|
26
|
-
|
|
27
|
-
const response2 = await fetch('http://localhost:13333/abc', {
|
|
28
|
-
headers: {
|
|
29
|
-
'Cookie': `connect.sid=${cookie}`
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const text2 = await response2.text();
|
|
33
|
-
console.log(text2);
|
|
34
|
-
|
|
35
|
-
process.exit(0);
|
|
36
|
-
|
|
37
|
-
});
|