ultimate-express 1.0.1 → 1.0.3
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/README.md +18 -1
- package/package.json +10 -6
- package/src/request.js +1 -1
- package/src/router.js +9 -3
- package/src/utils.js +5 -2
- 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,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
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// must support express.static() options
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
|
|
5
|
-
const app = express();
|
|
6
|
-
|
|
7
|
-
app.post('/abc', (req, res) => {
|
|
8
|
-
res.send('ok');
|
|
9
|
-
});
|
|
10
|
-
app.use('/static', express.static('tests/parts'));
|
|
11
|
-
app.use('/static2', express.static('tests/parts', { redirect: false }));
|
|
12
|
-
app.use('/static3', express.static('tests/parts', { index: 'index.pug' }));
|
|
13
|
-
app.use('/static4', express.static('tests/parts', { dotfiles: 'allow' }));
|
|
14
|
-
app.use('/static5', express.static('tests/parts', { dotfiles: 'deny' }));
|
|
15
|
-
app.use('/static6', express.static('tests/parts', { dotfiles: 'ignore' }));
|
|
16
|
-
app.use('/static7', express.static('tests/parts', { fallthrough: false }));
|
|
17
|
-
app.use('/static8', express.static('tests/parts', { etag: false }));
|
|
18
|
-
app.use('/static9', express.static('tests/parts', { extensions: ['jpg'] }));
|
|
19
|
-
app.use('/static10', express.static('tests/parts', { setHeaders: (res, path, stat) => {
|
|
20
|
-
console.log(path, stat.size);
|
|
21
|
-
res.set('X-Test', 'test');
|
|
22
|
-
} }));
|
|
23
|
-
|
|
24
|
-
app.use((err, req, res, next) => {
|
|
25
|
-
|
|
26
|
-
res.status(500).send(err);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
app.use((req, res, next) => {
|
|
30
|
-
|
|
31
|
-
res.status(404).send('404');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
app.listen(13333, async () => {
|
|
35
|
-
console.log('Server is running on port 13333');
|
|
36
|
-
|
|
37
|
-
const response = await fetch('http://localhost:13333/static', { redirect: 'manual' });
|
|
38
|
-
console.log(response.status, response.headers.get('Location'));
|
|
39
|
-
|
|
40
|
-
const response2 = await fetch('http://localhost:13333/static2', { redirect: 'manual' });
|
|
41
|
-
console.log(response2.status, response2.headers.get('Location'));
|
|
42
|
-
|
|
43
|
-
const response3 = await fetch('http://localhost:13333/static3');
|
|
44
|
-
console.log(response3.status);
|
|
45
|
-
|
|
46
|
-
const response4 = await fetch('http://localhost:13333/static4/.test/index.html');
|
|
47
|
-
console.log(response4.status, (await response4.text()).slice(0, 100));
|
|
48
|
-
|
|
49
|
-
const response5 = await fetch('http://localhost:13333/static5/.test/index.html');
|
|
50
|
-
console.log(response5.status, await response5.text());
|
|
51
|
-
|
|
52
|
-
const response6 = await fetch('http://localhost:13333/static6/.test/index.html');
|
|
53
|
-
console.log(response6.status, await response6.text());
|
|
54
|
-
|
|
55
|
-
const response7 = await fetch('http://localhost:13333/static7/assgdgeerdf.html');
|
|
56
|
-
console.log(response7.status, (await response7.text()).includes('ENOENT'));
|
|
57
|
-
|
|
58
|
-
const response8 = await fetch('http://localhost:13333/static8/index.html');
|
|
59
|
-
console.log(response8.headers.get('ETag'));
|
|
60
|
-
|
|
61
|
-
const response9 = await fetch('http://localhost:13333/static/index.html');
|
|
62
|
-
console.log(response9.headers.get('ETag'));
|
|
63
|
-
|
|
64
|
-
const response10 = await fetch('http://localhost:13333/static9/big');
|
|
65
|
-
console.log(response10.status, response10.headers.get('Content-Type'));
|
|
66
|
-
|
|
67
|
-
const response11 = await fetch('http://localhost:13333/static10/index.html');
|
|
68
|
-
console.log(response11.headers.get('X-Test'));
|
|
69
|
-
|
|
70
|
-
process.exit(0);
|
|
71
|
-
|
|
72
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// must support express.static()
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
|
|
5
|
-
const app = express();
|
|
6
|
-
|
|
7
|
-
app.post('/abc', (req, res) => {
|
|
8
|
-
res.send('ok');
|
|
9
|
-
});
|
|
10
|
-
app.use('/static', (req, res, next) => {
|
|
11
|
-
express.static('src')(req, res, e => {
|
|
12
|
-
console.log('caught', e);
|
|
13
|
-
next();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
app.use('/static', express.static('tests/parts'));
|
|
18
|
-
|
|
19
|
-
app.use((req, res, next) => {
|
|
20
|
-
res.status(404).send('404');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
app.listen(13333, async () => {
|
|
24
|
-
console.log('Server is running on port 13333');
|
|
25
|
-
|
|
26
|
-
const responses = await Promise.all([
|
|
27
|
-
fetch('http://localhost:13333/abc'),
|
|
28
|
-
fetch('http://localhost:13333/static/workers'),
|
|
29
|
-
fetch('http://localhost:13333/static/'),
|
|
30
|
-
fetch('http://localhost:13333/static/index.js?1'),
|
|
31
|
-
fetch('http://localhost:13333/static/../package.json'),
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
const texts = await Promise.all(responses.map(r => r.text()));
|
|
35
|
-
|
|
36
|
-
console.log(texts.map(t => t.slice(0, 30)));
|
|
37
|
-
|
|
38
|
-
process.exit(0);
|
|
39
|
-
|
|
40
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// must support method-override middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const methodOverride = require("method-override");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(methodOverride('X-HTTP-Method-Override'));
|
|
9
|
-
|
|
10
|
-
app.post('/abc', (req, res) => {
|
|
11
|
-
res.send(req.method+'1');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
app.use((req, res, next) => {
|
|
15
|
-
res.send(req.method+'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
|
-
method: 'GET',
|
|
23
|
-
headers: {
|
|
24
|
-
'X-HTTP-Method-Override': 'POST',
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const text = await response.text();
|
|
29
|
-
console.log(text);
|
|
30
|
-
|
|
31
|
-
process.exit(0);
|
|
32
|
-
|
|
33
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// must support multer middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const multer = require("multer");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
const upload = multer();
|
|
8
|
-
|
|
9
|
-
app.post('/abc', upload.none(), (req, res) => {
|
|
10
|
-
res.send(req.body);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
app.post('/file', upload.single('file'), (req, res) => {
|
|
14
|
-
res.send(req.file);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
app.listen(13333, async () => {
|
|
18
|
-
console.log('Server is running on port 13333');
|
|
19
|
-
|
|
20
|
-
const formData = new FormData();
|
|
21
|
-
formData.append('abc', '123');
|
|
22
|
-
|
|
23
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
24
|
-
method: 'POST',
|
|
25
|
-
body: formData
|
|
26
|
-
});
|
|
27
|
-
const text = await response.text();
|
|
28
|
-
console.log(text);
|
|
29
|
-
|
|
30
|
-
const formData2 = new FormData();
|
|
31
|
-
const file = new File([1, 2, 3], 'test.txt');
|
|
32
|
-
formData2.append('file', file);
|
|
33
|
-
|
|
34
|
-
const response2 = await fetch('http://localhost:13333/file', {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
body: formData2
|
|
37
|
-
});
|
|
38
|
-
const text2 = await response2.text();
|
|
39
|
-
console.log(text2);
|
|
40
|
-
|
|
41
|
-
process.exit(0);
|
|
42
|
-
|
|
43
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// must support multiple middlewares
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const bodyParser = require("body-parser");
|
|
5
|
-
const fileUpload = require("express-fileupload");
|
|
6
|
-
|
|
7
|
-
const app = express();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
app.post('/abc', bodyParser.raw(), fileUpload(), (req, res) => {
|
|
11
|
-
console.log(req.body, req.files);
|
|
12
|
-
res.send('ok');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
app.listen(13333, async () => {
|
|
16
|
-
console.log('Server is running on port 13333');
|
|
17
|
-
|
|
18
|
-
const formData = new FormData();
|
|
19
|
-
console.log('creating file');
|
|
20
|
-
const arr = [...new Array(1024 * 32)].map((_, i) => i % 256); // 32 KB
|
|
21
|
-
const file = new File(arr, 'test.txt');
|
|
22
|
-
console.log('appending file');
|
|
23
|
-
formData.append('file', file);
|
|
24
|
-
formData.append('text', 'hello');
|
|
25
|
-
console.log('sending request');
|
|
26
|
-
|
|
27
|
-
const response = await fetch('http://localhost:13333/abc', {
|
|
28
|
-
method: 'POST',
|
|
29
|
-
body: formData
|
|
30
|
-
});
|
|
31
|
-
console.log('reading response');
|
|
32
|
-
const text = await response.text();
|
|
33
|
-
console.log(text);
|
|
34
|
-
|
|
35
|
-
process.exit(0);
|
|
36
|
-
|
|
37
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// must support response-time middleware
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const responseTime = require("response-time");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(responseTime((req, res, time) => {
|
|
9
|
-
console.log(typeof time);
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
app.post('/abc', (req, res) => {
|
|
13
|
-
res.send('1');
|
|
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/abc', {
|
|
20
|
-
method: 'POST',
|
|
21
|
-
body: 'abc',
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const text = await response.text();
|
|
25
|
-
console.log(text);
|
|
26
|
-
|
|
27
|
-
process.exit(0);
|
|
28
|
-
|
|
29
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// must support serve index
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const serveStatic = require("serve-static");
|
|
5
|
-
const serveIndex = require("serve-index");
|
|
6
|
-
|
|
7
|
-
const app = express();
|
|
8
|
-
|
|
9
|
-
app.use('/static', serveStatic('src'), (req, res, next) => {
|
|
10
|
-
serveIndex('src')(req, res, next);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
app.get('/static/asdf', (req, res, next) => {
|
|
14
|
-
res.send(req.url);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
app.use((req, res, next) => {
|
|
18
|
-
res.status(404).send('404');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
app.listen(13333, async () => {
|
|
22
|
-
console.log('Server is running on port 13333');
|
|
23
|
-
|
|
24
|
-
const responses = await Promise.all([
|
|
25
|
-
fetch('http://localhost:13333/abc'),
|
|
26
|
-
fetch('http://localhost:13333/static'),
|
|
27
|
-
fetch('http://localhost:13333/static/workers'),
|
|
28
|
-
fetch('http://localhost:13333/static/index.js'),
|
|
29
|
-
fetch('http://localhost:13333/static/../package.json'),
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
const texts = await Promise.all(responses.map(r => r.text()));
|
|
33
|
-
|
|
34
|
-
console.log(texts.map(i => i.slice(0, 100)));
|
|
35
|
-
|
|
36
|
-
process.exit(0);
|
|
37
|
-
|
|
38
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// must support serve static
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const serveStatic = require("serve-static");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.post('/abc', (req, res) => {
|
|
9
|
-
res.send('ok');
|
|
10
|
-
});
|
|
11
|
-
app.use('/static', (req, res, next) => {
|
|
12
|
-
serveStatic('src')(req, res, () => {
|
|
13
|
-
console.log('caught');
|
|
14
|
-
next();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
app.use((req, res, next) => {
|
|
19
|
-
res.status(404).send('404');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
app.listen(13333, async () => {
|
|
23
|
-
console.log('Server is running on port 13333');
|
|
24
|
-
|
|
25
|
-
const responses = await Promise.all([
|
|
26
|
-
fetch('http://localhost:13333/abc'),
|
|
27
|
-
fetch('http://localhost:13333/static/workers'),
|
|
28
|
-
fetch('http://localhost:13333/static/index.js'),
|
|
29
|
-
fetch('http://localhost:13333/static/../package.json'),
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
const texts = await Promise.all(responses.map(r => r.text()));
|
|
33
|
-
|
|
34
|
-
console.log(texts);
|
|
35
|
-
|
|
36
|
-
process.exit(0);
|
|
37
|
-
|
|
38
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// must support vhost middleware
|
|
2
|
-
|
|
3
|
-
const net = require("net");
|
|
4
|
-
|
|
5
|
-
async function sendRequest(method, url, customHost) {
|
|
6
|
-
// arrayHeaders is an array of [key, value] pairs
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const client = new net.Socket();
|
|
9
|
-
const [host, port] = url.split('://')[1].split('/')[0].split(':');
|
|
10
|
-
const path = '/' + url.split('/').slice(3).join('/');
|
|
11
|
-
|
|
12
|
-
client.connect(parseInt(port), host, () => {
|
|
13
|
-
let request = `${method} ${path} HTTP/1.1\r\n`;
|
|
14
|
-
request += `Host: ${customHost}\r\n`;
|
|
15
|
-
|
|
16
|
-
request += '\r\n';
|
|
17
|
-
|
|
18
|
-
client.on('data', (data) => {
|
|
19
|
-
resolve(data.toString().split('\r\n\r\n')[1]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
client.write(request);
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const express = require("express");
|
|
29
|
-
const vhost = require("vhost");
|
|
30
|
-
|
|
31
|
-
const app = express();
|
|
32
|
-
|
|
33
|
-
app.use(vhost('*.example.com', (req, res) => {
|
|
34
|
-
res.send('Hello from example.com');
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
app.get('/abc', (req, res) => {
|
|
38
|
-
res.send('hi');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
app.listen(13333, async () => {
|
|
42
|
-
console.log('Server is running on port 13333');
|
|
43
|
-
|
|
44
|
-
console.log(await sendRequest('GET', 'http://localhost:13333/abc', 'example.com'));
|
|
45
|
-
console.log(await sendRequest('GET', 'http://localhost:13333/abc', 'sub.example.com'));
|
|
46
|
-
console.log(await sendRequest('GET', 'http://localhost:13333/abc', 'localhost.com'));
|
|
47
|
-
|
|
48
|
-
process.exit(0);
|
|
49
|
-
|
|
50
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
});
|