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.
Files changed (200) hide show
  1. package/.github/workflows/test.yml +27 -0
  2. package/EXPRESS_LICENSE +26 -0
  3. package/README.md +269 -0
  4. package/package.json +76 -0
  5. package/src/application.js +295 -0
  6. package/src/index.js +23 -0
  7. package/src/middlewares.js +95 -0
  8. package/src/request.js +324 -0
  9. package/src/response.js +686 -0
  10. package/src/router.js +490 -0
  11. package/src/utils.js +285 -0
  12. package/src/view.js +103 -0
  13. package/src/workers/fs.js +14 -0
  14. package/tests/index.js +64 -0
  15. package/tests/parts/.test/index.html +11 -0
  16. package/tests/parts/big.jpg +0 -0
  17. package/tests/parts/index.art +12 -0
  18. package/tests/parts/index.dot +12 -0
  19. package/tests/parts/index.ejs +12 -0
  20. package/tests/parts/index.handlebars +2 -0
  21. package/tests/parts/index.html +12 -0
  22. package/tests/parts/index.mustache +12 -0
  23. package/tests/parts/index.pug +6 -0
  24. package/tests/parts/index.swig +12 -0
  25. package/tests/parts/layouts/main.handlebars +12 -0
  26. package/tests/preload.cjs +5 -0
  27. package/tests/singular.js +41 -0
  28. package/tests/tests/app/app-engine.js +8 -0
  29. package/tests/tests/app/app-on-mount.js +24 -0
  30. package/tests/tests/app/app-path.js +21 -0
  31. package/tests/tests/app/app-route.js +30 -0
  32. package/tests/tests/app/options.js +16 -0
  33. package/tests/tests/app/setting-inheritance.js +16 -0
  34. package/tests/tests/engines/art-template.js +33 -0
  35. package/tests/tests/engines/dot.js +28 -0
  36. package/tests/tests/engines/ejs.js +25 -0
  37. package/tests/tests/engines/handlebars.js +28 -0
  38. package/tests/tests/engines/mustache.js +28 -0
  39. package/tests/tests/engines/pug.js +25 -0
  40. package/tests/tests/engines/swig.js +28 -0
  41. package/tests/tests/errors/error-handling-middleware.js +22 -0
  42. package/tests/tests/errors/next-error-optimized.js +26 -0
  43. package/tests/tests/errors/next-error.js +26 -0
  44. package/tests/tests/errors/unexpected-error-handling.js +18 -0
  45. package/tests/tests/listen/listen-random.js +11 -0
  46. package/tests/tests/listen/listen-specific.js +17 -0
  47. package/tests/tests/middlewares/body-json.js +31 -0
  48. package/tests/tests/middlewares/body-raw-deflate.js +43 -0
  49. package/tests/tests/middlewares/body-raw-gzip.js +43 -0
  50. package/tests/tests/middlewares/body-raw.js +41 -0
  51. package/tests/tests/middlewares/body-text.js +27 -0
  52. package/tests/tests/middlewares/body-urlencoded.js +30 -0
  53. package/tests/tests/middlewares/cookie-parser-signed.js +31 -0
  54. package/tests/tests/middlewares/cookie-parser.js +28 -0
  55. package/tests/tests/middlewares/cookie-session.js +40 -0
  56. package/tests/tests/middlewares/cors.js +29 -0
  57. package/tests/tests/middlewares/errorhandler.js +26 -0
  58. package/tests/tests/middlewares/express-fileupload-temp.js +46 -0
  59. package/tests/tests/middlewares/express-fileupload.js +28 -0
  60. package/tests/tests/middlewares/express-rate-limit.js +33 -0
  61. package/tests/tests/middlewares/express-session.js +37 -0
  62. package/tests/tests/middlewares/express-static-options.js +72 -0
  63. package/tests/tests/middlewares/express-static.js +40 -0
  64. package/tests/tests/middlewares/method-override.js +33 -0
  65. package/tests/tests/middlewares/multer.js +43 -0
  66. package/tests/tests/middlewares/multiple-middlewares.js +37 -0
  67. package/tests/tests/middlewares/response-time.js +29 -0
  68. package/tests/tests/middlewares/serve-index.js +38 -0
  69. package/tests/tests/middlewares/serve-static.js +38 -0
  70. package/tests/tests/middlewares/vhost.js +50 -0
  71. package/tests/tests/params/array-param.js +30 -0
  72. package/tests/tests/params/nested-params.js +24 -0
  73. package/tests/tests/params/param-errors.js +56 -0
  74. package/tests/tests/params/param-function.js +49 -0
  75. package/tests/tests/params/param-next-route.js +48 -0
  76. package/tests/tests/params/param-optimized.js +38 -0
  77. package/tests/tests/params/param-use.js +39 -0
  78. package/tests/tests/params/param.js +68 -0
  79. package/tests/tests/params/params-regex.js +26 -0
  80. package/tests/tests/params/params-use.js +20 -0
  81. package/tests/tests/params/params.js +35 -0
  82. package/tests/tests/req/req-accepts-charsets.js +40 -0
  83. package/tests/tests/req/req-accepts-encodings.js +36 -0
  84. package/tests/tests/req/req-accepts-languages.js +41 -0
  85. package/tests/tests/req/req-accepts.js +41 -0
  86. package/tests/tests/req/req-app.js +17 -0
  87. package/tests/tests/req/req-baseurl.js +38 -0
  88. package/tests/tests/req/req-connection.js +19 -0
  89. package/tests/tests/req/req-fresh.js +59 -0
  90. package/tests/tests/req/req-get.js +78 -0
  91. package/tests/tests/req/req-headers-distinct.js +72 -0
  92. package/tests/tests/req/req-headers.js +72 -0
  93. package/tests/tests/req/req-host.js +45 -0
  94. package/tests/tests/req/req-hostname.js +45 -0
  95. package/tests/tests/req/req-ip.js +19 -0
  96. package/tests/tests/req/req-is.js +44 -0
  97. package/tests/tests/req/req-original-url.js +29 -0
  98. package/tests/tests/req/req-param.js +29 -0
  99. package/tests/tests/req/req-protocol.js +20 -0
  100. package/tests/tests/req/req-query.js +23 -0
  101. package/tests/tests/req/req-range.js +48 -0
  102. package/tests/tests/req/req-raw-headers.js +72 -0
  103. package/tests/tests/req/req-subdomains.js +48 -0
  104. package/tests/tests/req/req-url-nested.js +27 -0
  105. package/tests/tests/req/req-url-optimized-router.js +26 -0
  106. package/tests/tests/req/req-url-optimized.js +23 -0
  107. package/tests/tests/req/req-url.js +36 -0
  108. package/tests/tests/req/req-xhr.js +23 -0
  109. package/tests/tests/res/head-content-length.js +18 -0
  110. package/tests/tests/res/head.js +47 -0
  111. package/tests/tests/res/injecting.js +25 -0
  112. package/tests/tests/res/piping.js +23 -0
  113. package/tests/tests/res/res-app.js +17 -0
  114. package/tests/tests/res/res-append.js +24 -0
  115. package/tests/tests/res/res-attachment.js +19 -0
  116. package/tests/tests/res/res-clear-cookie.js +18 -0
  117. package/tests/tests/res/res-cookie.js +22 -0
  118. package/tests/tests/res/res-download.js +36 -0
  119. package/tests/tests/res/res-format.js +57 -0
  120. package/tests/tests/res/res-get.js +18 -0
  121. package/tests/tests/res/res-headers-sent.js +18 -0
  122. package/tests/tests/res/res-json.js +17 -0
  123. package/tests/tests/res/res-jsonp.js +25 -0
  124. package/tests/tests/res/res-links.js +21 -0
  125. package/tests/tests/res/res-location.js +34 -0
  126. package/tests/tests/res/res-redirect.js +46 -0
  127. package/tests/tests/res/res-remove-header.js +19 -0
  128. package/tests/tests/res/res-send-file.js +17 -0
  129. package/tests/tests/res/res-send-status.js +17 -0
  130. package/tests/tests/res/res-send.js +69 -0
  131. package/tests/tests/res/res-set.js +28 -0
  132. package/tests/tests/res/res-status.js +18 -0
  133. package/tests/tests/res/res-type.js +19 -0
  134. package/tests/tests/res/res-vary.js +19 -0
  135. package/tests/tests/res/res-write.js +29 -0
  136. package/tests/tests/routers/complex-routers.js +34 -0
  137. package/tests/tests/routers/empty-router.js +25 -0
  138. package/tests/tests/routers/lot-of-routes.js +38 -0
  139. package/tests/tests/routers/mergeparams.js +42 -0
  140. package/tests/tests/routers/nested-routers.js +52 -0
  141. package/tests/tests/routers/router-options.js +68 -0
  142. package/tests/tests/routers/routers.js +45 -0
  143. package/tests/tests/routers/simple-routers.js +35 -0
  144. package/tests/tests/routing/all.js +47 -0
  145. package/tests/tests/routing/array-arguments.js +35 -0
  146. package/tests/tests/routing/array-use.js +33 -0
  147. package/tests/tests/routing/async-use.js +25 -0
  148. package/tests/tests/routing/complex-routes.js +50 -0
  149. package/tests/tests/routing/lot-of-param-routes.js +26 -0
  150. package/tests/tests/routing/lot-of-routes.js +59 -0
  151. package/tests/tests/routing/next-existent-optimized-route.js +29 -0
  152. package/tests/tests/routing/next-existent-route.js +29 -0
  153. package/tests/tests/routing/next-nonexistent-optimized-route.js +19 -0
  154. package/tests/tests/routing/next-nonexistent-route.js +19 -0
  155. package/tests/tests/routing/next-special-cases.js +54 -0
  156. package/tests/tests/routing/next-unoptimized.js +39 -0
  157. package/tests/tests/routing/no-path-use.js +29 -0
  158. package/tests/tests/routing/non-string-routes.js +27 -0
  159. package/tests/tests/routing/req-multiple-mountpaths.js +34 -0
  160. package/tests/tests/routing/simple-routes.js +29 -0
  161. package/tests/tests/routing/simple-use.js +52 -0
  162. package/tests/tests/routing/some-middlewares.js +27 -0
  163. package/tests/tests/routing/special-characters.js +28 -0
  164. package/tests/tests/routing/star.js +31 -0
  165. package/tests/tests/routing/sub-apps.js +32 -0
  166. package/tests/tests/routing/trailing-slash.js +37 -0
  167. package/tests/tests/routing/weird-route-start.js +18 -0
  168. package/tests/tests/send-file/accept-ranges.js +26 -0
  169. package/tests/tests/send-file/callback.js +23 -0
  170. package/tests/tests/send-file/default-error-routing.js +21 -0
  171. package/tests/tests/send-file/dotfiles.js +24 -0
  172. package/tests/tests/send-file/etag.js +19 -0
  173. package/tests/tests/send-file/fs-threads.js +39 -0
  174. package/tests/tests/send-file/head.js +49 -0
  175. package/tests/tests/send-file/headers.js +23 -0
  176. package/tests/tests/send-file/if-match.js +31 -0
  177. package/tests/tests/send-file/if-range.js +37 -0
  178. package/tests/tests/send-file/if-unmodified-since.js +32 -0
  179. package/tests/tests/send-file/immutable.js +22 -0
  180. package/tests/tests/send-file/large-file.js +19 -0
  181. package/tests/tests/send-file/last-modified.js +21 -0
  182. package/tests/tests/send-file/max-age.js +21 -0
  183. package/tests/tests/send-file/path-traversal.js +35 -0
  184. package/tests/tests/send-file/range.js +57 -0
  185. package/tests/tests/send-file/simple.js +18 -0
  186. package/tests/tests/settings/case-sensitive-routing.js +48 -0
  187. package/tests/tests/settings/env-errors.js +38 -0
  188. package/tests/tests/settings/etag.js +36 -0
  189. package/tests/tests/settings/json-escape.js +45 -0
  190. package/tests/tests/settings/json-replacer.js +50 -0
  191. package/tests/tests/settings/json-spaces.js +44 -0
  192. package/tests/tests/settings/query-parser.js +45 -0
  193. package/tests/tests/settings/strict-routing.js +64 -0
  194. package/tests/tests/settings/subdomain-offset.js +38 -0
  195. package/tests/tests/settings/trust-proxy-host.js +58 -0
  196. package/tests/tests/settings/trust-proxy-ip.js +58 -0
  197. package/tests/tests/settings/trust-proxy-ips.js +58 -0
  198. package/tests/tests/settings/trust-proxy-protocol.js +46 -0
  199. package/tests/tests/settings/x-powered-by.js +32 -0
  200. package/tests/uws.js +14 -0
@@ -0,0 +1,21 @@
1
+ // must support app.path()
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+ const app2 = express();
7
+ const app3 = express();
8
+ const router = express.Router();
9
+
10
+ app.use('/abc', app2);
11
+ app2.use('/def', app3);
12
+
13
+ app.use((req, res, next) => {
14
+ res.send('404');
15
+ });
16
+
17
+ console.log(app.path());
18
+ console.log(app2.path());
19
+ console.log(app3.path());
20
+ console.log(router?.path?.());
21
+ console.log(app.mountpath, app2.mountpath, app3.mountpath);
@@ -0,0 +1,30 @@
1
+ // must support app.route()
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+
7
+ app.get('/asdf', (req, res) => {
8
+ res.send('asdf');
9
+ });
10
+
11
+ app.route('/test')
12
+ .get((req, res) => {
13
+ res.send('test1');
14
+ })
15
+ .post((req, res) => {
16
+ res.send('test2');
17
+ });
18
+
19
+ app.listen(13333, async () => {
20
+ console.log('Server is running on port 13333');
21
+
22
+ let outputs = await Promise.all([
23
+ fetch('http://localhost:13333/asdf').then(res => res.text()),
24
+ fetch('http://localhost:13333/test').then(res => res.text()),
25
+ fetch('http://localhost:13333/test', { method: 'POST' }).then(res => res.text()),
26
+ ]);
27
+
28
+ console.log(outputs.join(' '));
29
+ process.exit(0);
30
+ });
@@ -0,0 +1,16 @@
1
+ // must support setting and getting options
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+
7
+ app.set('case sensitive routing', true);
8
+ console.log(app.get('case sensitive routing'));
9
+
10
+ app.enable('x-powered-by');
11
+ console.log(app.enabled('x-powered-by'));
12
+
13
+ app.disable('x-powered-by');
14
+ console.log(app.enabled('x-powered-by'));
15
+
16
+ console.log(app.disabled('x-powered-by'));
@@ -0,0 +1,16 @@
1
+ // must support app.path()
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+ const app2 = express();
7
+
8
+ app.set('case sensitive routing', true);
9
+ app.set('jsonp callback name', 'cb');
10
+
11
+ app.use('/abc', app2);
12
+
13
+
14
+ console.log(app2.get('case sensitive routing'));
15
+ console.log(app2.get('jsonp callback name'));
16
+
@@ -0,0 +1,33 @@
1
+ // must support art template engine
2
+
3
+ const express = require("express");
4
+ const artTemplate = require("express-art-template");
5
+
6
+ const app = express();
7
+
8
+ app.engine('art', artTemplate);
9
+ app.set('views', 'tests/parts');
10
+ app.set('view engine', 'art');
11
+ app.set('view options', {
12
+ debug: process.env.NODE_ENV !== 'production',
13
+ ignore: ['Math', 'Date', 'JSON', 'encodeURIComponent'],
14
+ minimize: false
15
+ });
16
+
17
+ app.get('/test', (req, res) => {
18
+ res.locals.asdf = 'locals test';
19
+ res.render('index', { title: 'Hey', message: 'Hello there!' });
20
+ });
21
+
22
+ app.use((err, req, res, next) => {
23
+ console.log(err);
24
+ res.status(500).send(`whoops!`);
25
+ });
26
+
27
+ app.listen(13333, async () => {
28
+ console.log('Server is running on port 13333');
29
+
30
+ const response = await fetch('http://localhost:13333/test').then(res => res.text());
31
+ console.log(response);
32
+ process.exit(0);
33
+ });
@@ -0,0 +1,28 @@
1
+ // must support doT engine
2
+
3
+ const express = require("express");
4
+ const dot = require("express-dot-engine");
5
+
6
+ const app = express();
7
+
8
+ app.engine('dot', dot.__express);
9
+ app.set('view engine', 'dot');
10
+ app.set('views', 'tests/parts');
11
+
12
+ app.get('/test', (req, res) => {
13
+ res.locals.asdf = 'locals test';
14
+ res.render('index.ejs', { title: 'Hey', message: 'Hello there!' });
15
+ });
16
+
17
+ app.use((err, req, res, next) => {
18
+ console.log(err);
19
+ res.status(500).send(`whoops!`);
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/test').then(res => res.text());
26
+ console.log(response);
27
+ process.exit(0);
28
+ });
@@ -0,0 +1,25 @@
1
+ // must support ejs engine
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+ app.set('view engine', 'ejs');
7
+ app.set('views', 'tests/parts');
8
+
9
+ app.get('/test', (req, res) => {
10
+ res.locals.asdf = 'locals test';
11
+ res.render('index.ejs', { title: 'Hey', message: 'Hello there!' });
12
+ });
13
+
14
+ app.use((err, req, res, next) => {
15
+ console.log(err);
16
+ res.status(500).send(`whoops!`);
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/test').then(res => res.text());
23
+ console.log(response);
24
+ process.exit(0);
25
+ });
@@ -0,0 +1,28 @@
1
+ // must support handlebars engine
2
+
3
+ const express = require("express");
4
+ const { engine } = require("express-handlebars");
5
+
6
+ const app = express();
7
+
8
+ app.engine('handlebars', engine());
9
+ app.set('view engine', 'handlebars');
10
+ app.set('views', 'tests/parts');
11
+
12
+ app.get('/test', (req, res) => {
13
+ res.locals.asdf = 'locals test';
14
+ res.render('index', { title: 'Hey', message: 'Hello there!' });
15
+ });
16
+
17
+ app.use((err, req, res, next) => {
18
+ console.log(err);
19
+ res.status(500).send(`whoops!`);
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/test').then(res => res.text());
26
+ console.log(response);
27
+ process.exit(0);
28
+ });
@@ -0,0 +1,28 @@
1
+ // must support mustache engine
2
+
3
+ const express = require("express");
4
+ const mustacheExpress = require("mustache-express");
5
+
6
+ const app = express();
7
+
8
+ app.engine('mustache', mustacheExpress());
9
+ app.set('view engine', 'mustache');
10
+ app.set('views', 'tests/parts');
11
+
12
+ app.get('/test', (req, res) => {
13
+ res.locals.asdf = 'locals test';
14
+ res.render('index', { title: 'Hey', message: 'Hello there!' });
15
+ });
16
+
17
+ app.use((err, req, res, next) => {
18
+ console.log(err);
19
+ res.status(500).send(`whoops!`);
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/test').then(res => res.text());
26
+ console.log(response);
27
+ process.exit(0);
28
+ });
@@ -0,0 +1,25 @@
1
+ // must support pug engine
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+ app.set('view engine', 'pug');
7
+ app.set('views', 'tests/parts');
8
+
9
+ app.get('/test', (req, res) => {
10
+ res.locals.asdf = 'locals test';
11
+ res.render('index', { title: 'Hey', message: 'Hello there!' });
12
+ });
13
+
14
+ app.use((err, req, res, next) => {
15
+ console.log(err);
16
+ res.status(500).send(`whoops!`);
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/test').then(res => res.text());
23
+ console.log(response);
24
+ process.exit(0);
25
+ });
@@ -0,0 +1,28 @@
1
+ // must support swig engine
2
+
3
+ const express = require("express");
4
+ const swig = require("swig");
5
+
6
+ const app = express();
7
+
8
+ app.engine('swig', swig.renderFile);
9
+ app.set('view engine', 'swig');
10
+ app.set('views', 'tests/parts');
11
+
12
+ app.get('/test', (req, res) => {
13
+ res.locals.asdf = 'locals test';
14
+ res.render('index', { title: 'Hey', message: 'Hello there!' });
15
+ });
16
+
17
+ app.use((err, req, res, next) => {
18
+ console.log(err);
19
+ res.status(500).send(`whoops!`);
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/test').then(res => res.text());
26
+ console.log(response);
27
+ process.exit(0);
28
+ });
@@ -0,0 +1,22 @@
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
+ });
@@ -0,0 +1,26 @@
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
+ });
@@ -0,0 +1,26 @@
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
+ });
@@ -0,0 +1,18 @@
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
+ });
@@ -0,0 +1,11 @@
1
+ // must open random port
2
+
3
+ const express = require("express");
4
+
5
+ const app = express();
6
+
7
+ app.listen(() => {
8
+ console.log('Server is running on random port');
9
+
10
+ process.exit(0);
11
+ });
@@ -0,0 +1,17 @@
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
+ });
@@ -0,0 +1,31 @@
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
+ });
@@ -0,0 +1,43 @@
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
+ });
@@ -0,0 +1,43 @@
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
+ });
@@ -0,0 +1,41 @@
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
+ });
@@ -0,0 +1,27 @@
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
+ });
@@ -0,0 +1,30 @@
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
+ });
@@ -0,0 +1,31 @@
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
+ });