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.
Files changed (193) hide show
  1. package/README.md +18 -1
  2. package/package.json +10 -6
  3. package/src/request.js +1 -1
  4. package/src/router.js +9 -3
  5. package/src/utils.js +5 -2
  6. package/.github/workflows/test.yml +0 -27
  7. package/tests/index.js +0 -64
  8. package/tests/parts/.test/index.html +0 -11
  9. package/tests/parts/big.jpg +0 -0
  10. package/tests/parts/index.art +0 -12
  11. package/tests/parts/index.dot +0 -12
  12. package/tests/parts/index.ejs +0 -12
  13. package/tests/parts/index.handlebars +0 -2
  14. package/tests/parts/index.html +0 -12
  15. package/tests/parts/index.mustache +0 -12
  16. package/tests/parts/index.pug +0 -6
  17. package/tests/parts/index.swig +0 -12
  18. package/tests/parts/layouts/main.handlebars +0 -12
  19. package/tests/preload.cjs +0 -5
  20. package/tests/singular.js +0 -41
  21. package/tests/tests/app/app-engine.js +0 -8
  22. package/tests/tests/app/app-on-mount.js +0 -24
  23. package/tests/tests/app/app-path.js +0 -21
  24. package/tests/tests/app/app-route.js +0 -30
  25. package/tests/tests/app/options.js +0 -16
  26. package/tests/tests/app/setting-inheritance.js +0 -16
  27. package/tests/tests/engines/art-template.js +0 -33
  28. package/tests/tests/engines/dot.js +0 -28
  29. package/tests/tests/engines/ejs.js +0 -25
  30. package/tests/tests/engines/handlebars.js +0 -28
  31. package/tests/tests/engines/mustache.js +0 -28
  32. package/tests/tests/engines/pug.js +0 -25
  33. package/tests/tests/engines/swig.js +0 -28
  34. package/tests/tests/errors/error-handling-middleware.js +0 -22
  35. package/tests/tests/errors/next-error-optimized.js +0 -26
  36. package/tests/tests/errors/next-error.js +0 -26
  37. package/tests/tests/errors/unexpected-error-handling.js +0 -18
  38. package/tests/tests/listen/listen-random.js +0 -11
  39. package/tests/tests/listen/listen-specific.js +0 -17
  40. package/tests/tests/middlewares/body-json.js +0 -31
  41. package/tests/tests/middlewares/body-raw-deflate.js +0 -43
  42. package/tests/tests/middlewares/body-raw-gzip.js +0 -43
  43. package/tests/tests/middlewares/body-raw.js +0 -41
  44. package/tests/tests/middlewares/body-text.js +0 -27
  45. package/tests/tests/middlewares/body-urlencoded.js +0 -30
  46. package/tests/tests/middlewares/cookie-parser-signed.js +0 -31
  47. package/tests/tests/middlewares/cookie-parser.js +0 -28
  48. package/tests/tests/middlewares/cookie-session.js +0 -40
  49. package/tests/tests/middlewares/cors.js +0 -29
  50. package/tests/tests/middlewares/errorhandler.js +0 -26
  51. package/tests/tests/middlewares/express-fileupload-temp.js +0 -46
  52. package/tests/tests/middlewares/express-fileupload.js +0 -28
  53. package/tests/tests/middlewares/express-rate-limit.js +0 -33
  54. package/tests/tests/middlewares/express-session.js +0 -37
  55. package/tests/tests/middlewares/express-static-options.js +0 -72
  56. package/tests/tests/middlewares/express-static.js +0 -40
  57. package/tests/tests/middlewares/method-override.js +0 -33
  58. package/tests/tests/middlewares/multer.js +0 -43
  59. package/tests/tests/middlewares/multiple-middlewares.js +0 -37
  60. package/tests/tests/middlewares/response-time.js +0 -29
  61. package/tests/tests/middlewares/serve-index.js +0 -38
  62. package/tests/tests/middlewares/serve-static.js +0 -38
  63. package/tests/tests/middlewares/vhost.js +0 -50
  64. package/tests/tests/params/array-param.js +0 -30
  65. package/tests/tests/params/nested-params.js +0 -24
  66. package/tests/tests/params/param-errors.js +0 -56
  67. package/tests/tests/params/param-function.js +0 -49
  68. package/tests/tests/params/param-next-route.js +0 -48
  69. package/tests/tests/params/param-optimized.js +0 -38
  70. package/tests/tests/params/param-use.js +0 -39
  71. package/tests/tests/params/param.js +0 -68
  72. package/tests/tests/params/params-regex.js +0 -26
  73. package/tests/tests/params/params-use.js +0 -20
  74. package/tests/tests/params/params.js +0 -35
  75. package/tests/tests/req/req-accepts-charsets.js +0 -40
  76. package/tests/tests/req/req-accepts-encodings.js +0 -36
  77. package/tests/tests/req/req-accepts-languages.js +0 -41
  78. package/tests/tests/req/req-accepts.js +0 -41
  79. package/tests/tests/req/req-app.js +0 -17
  80. package/tests/tests/req/req-baseurl.js +0 -38
  81. package/tests/tests/req/req-connection.js +0 -19
  82. package/tests/tests/req/req-fresh.js +0 -59
  83. package/tests/tests/req/req-get.js +0 -78
  84. package/tests/tests/req/req-headers-distinct.js +0 -72
  85. package/tests/tests/req/req-headers.js +0 -72
  86. package/tests/tests/req/req-host.js +0 -45
  87. package/tests/tests/req/req-hostname.js +0 -45
  88. package/tests/tests/req/req-ip.js +0 -19
  89. package/tests/tests/req/req-is.js +0 -44
  90. package/tests/tests/req/req-original-url.js +0 -29
  91. package/tests/tests/req/req-param.js +0 -29
  92. package/tests/tests/req/req-protocol.js +0 -20
  93. package/tests/tests/req/req-query.js +0 -23
  94. package/tests/tests/req/req-range.js +0 -48
  95. package/tests/tests/req/req-raw-headers.js +0 -72
  96. package/tests/tests/req/req-subdomains.js +0 -48
  97. package/tests/tests/req/req-url-nested.js +0 -27
  98. package/tests/tests/req/req-url-optimized-router.js +0 -26
  99. package/tests/tests/req/req-url-optimized.js +0 -23
  100. package/tests/tests/req/req-url.js +0 -36
  101. package/tests/tests/req/req-xhr.js +0 -23
  102. package/tests/tests/res/head-content-length.js +0 -18
  103. package/tests/tests/res/head.js +0 -47
  104. package/tests/tests/res/injecting.js +0 -25
  105. package/tests/tests/res/piping.js +0 -23
  106. package/tests/tests/res/res-app.js +0 -17
  107. package/tests/tests/res/res-append.js +0 -24
  108. package/tests/tests/res/res-attachment.js +0 -19
  109. package/tests/tests/res/res-clear-cookie.js +0 -18
  110. package/tests/tests/res/res-cookie.js +0 -22
  111. package/tests/tests/res/res-download.js +0 -36
  112. package/tests/tests/res/res-format.js +0 -57
  113. package/tests/tests/res/res-get.js +0 -18
  114. package/tests/tests/res/res-headers-sent.js +0 -18
  115. package/tests/tests/res/res-json.js +0 -17
  116. package/tests/tests/res/res-jsonp.js +0 -25
  117. package/tests/tests/res/res-links.js +0 -21
  118. package/tests/tests/res/res-location.js +0 -34
  119. package/tests/tests/res/res-redirect.js +0 -46
  120. package/tests/tests/res/res-remove-header.js +0 -19
  121. package/tests/tests/res/res-send-file.js +0 -17
  122. package/tests/tests/res/res-send-status.js +0 -17
  123. package/tests/tests/res/res-send.js +0 -69
  124. package/tests/tests/res/res-set.js +0 -28
  125. package/tests/tests/res/res-status.js +0 -18
  126. package/tests/tests/res/res-type.js +0 -19
  127. package/tests/tests/res/res-vary.js +0 -19
  128. package/tests/tests/res/res-write.js +0 -29
  129. package/tests/tests/routers/complex-routers.js +0 -34
  130. package/tests/tests/routers/empty-router.js +0 -25
  131. package/tests/tests/routers/lot-of-routes.js +0 -38
  132. package/tests/tests/routers/mergeparams.js +0 -42
  133. package/tests/tests/routers/nested-routers.js +0 -52
  134. package/tests/tests/routers/router-options.js +0 -68
  135. package/tests/tests/routers/routers.js +0 -45
  136. package/tests/tests/routers/simple-routers.js +0 -35
  137. package/tests/tests/routing/all.js +0 -47
  138. package/tests/tests/routing/array-arguments.js +0 -35
  139. package/tests/tests/routing/array-use.js +0 -33
  140. package/tests/tests/routing/async-use.js +0 -25
  141. package/tests/tests/routing/complex-routes.js +0 -50
  142. package/tests/tests/routing/lot-of-param-routes.js +0 -26
  143. package/tests/tests/routing/lot-of-routes.js +0 -59
  144. package/tests/tests/routing/next-existent-optimized-route.js +0 -29
  145. package/tests/tests/routing/next-existent-route.js +0 -29
  146. package/tests/tests/routing/next-nonexistent-optimized-route.js +0 -19
  147. package/tests/tests/routing/next-nonexistent-route.js +0 -19
  148. package/tests/tests/routing/next-special-cases.js +0 -54
  149. package/tests/tests/routing/next-unoptimized.js +0 -39
  150. package/tests/tests/routing/no-path-use.js +0 -29
  151. package/tests/tests/routing/non-string-routes.js +0 -27
  152. package/tests/tests/routing/req-multiple-mountpaths.js +0 -34
  153. package/tests/tests/routing/simple-routes.js +0 -29
  154. package/tests/tests/routing/simple-use.js +0 -52
  155. package/tests/tests/routing/some-middlewares.js +0 -27
  156. package/tests/tests/routing/special-characters.js +0 -28
  157. package/tests/tests/routing/star.js +0 -31
  158. package/tests/tests/routing/sub-apps.js +0 -32
  159. package/tests/tests/routing/trailing-slash.js +0 -37
  160. package/tests/tests/routing/weird-route-start.js +0 -18
  161. package/tests/tests/send-file/accept-ranges.js +0 -26
  162. package/tests/tests/send-file/callback.js +0 -23
  163. package/tests/tests/send-file/default-error-routing.js +0 -21
  164. package/tests/tests/send-file/dotfiles.js +0 -24
  165. package/tests/tests/send-file/etag.js +0 -19
  166. package/tests/tests/send-file/fs-threads.js +0 -39
  167. package/tests/tests/send-file/head.js +0 -49
  168. package/tests/tests/send-file/headers.js +0 -23
  169. package/tests/tests/send-file/if-match.js +0 -31
  170. package/tests/tests/send-file/if-range.js +0 -37
  171. package/tests/tests/send-file/if-unmodified-since.js +0 -32
  172. package/tests/tests/send-file/immutable.js +0 -22
  173. package/tests/tests/send-file/large-file.js +0 -19
  174. package/tests/tests/send-file/last-modified.js +0 -21
  175. package/tests/tests/send-file/max-age.js +0 -21
  176. package/tests/tests/send-file/path-traversal.js +0 -35
  177. package/tests/tests/send-file/range.js +0 -57
  178. package/tests/tests/send-file/simple.js +0 -18
  179. package/tests/tests/settings/case-sensitive-routing.js +0 -48
  180. package/tests/tests/settings/env-errors.js +0 -38
  181. package/tests/tests/settings/etag.js +0 -36
  182. package/tests/tests/settings/json-escape.js +0 -45
  183. package/tests/tests/settings/json-replacer.js +0 -50
  184. package/tests/tests/settings/json-spaces.js +0 -44
  185. package/tests/tests/settings/query-parser.js +0 -45
  186. package/tests/tests/settings/strict-routing.js +0 -64
  187. package/tests/tests/settings/subdomain-offset.js +0 -38
  188. package/tests/tests/settings/trust-proxy-host.js +0 -58
  189. package/tests/tests/settings/trust-proxy-ip.js +0 -58
  190. package/tests/tests/settings/trust-proxy-ips.js +0 -58
  191. package/tests/tests/settings/trust-proxy-protocol.js +0 -46
  192. package/tests/tests/settings/x-powered-by.js +0 -32
  193. package/tests/uws.js +0 -14
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # µExpress
1
+ # µExpress / Ultimate Express
2
2
 
3
3
  The *Ultimate* Express. Fastest http server with **full** Express compatibility, based on µWebSockets.
4
4
 
@@ -19,6 +19,21 @@ Similar projects based on uWebSockets:
19
19
  - `hyper-express` - while having a similar API to Express, it's very far from being a drop-in replacement, and implements most of the functionality differently. This creates a lot of random quirks and issues, making the switch quite difficult. Built in middlewares are also very different.
20
20
  - `uwebsockets-express` - this library is closer to being a drop-in replacement, but misses a lot of APIs, depends on Express by calling it's methods under the hood and doesn't try to optimize routing by using native uWS router.
21
21
 
22
+ ## Performance
23
+
24
+ Tested using [wrk](https://github.com/wg/wrk) (`-d 60 -t 1 -c 200`). Etag was disabled in both Express and µExpress. Tested on Ubuntu 22.04, Node.js 20.17.0, AMD Ryzen 5 3600, 64GB RAM.
25
+
26
+ | Test | Path | Express req/sec | µExpress req/sec | Express throughput | µExpress throughput | µExpress speedup |
27
+ | --------------------------- | ---------------- | --------------- | ---------------- | ------------------ | ------------------- | ---------------- |
28
+ | routing/simple-routes.js | / | 10.90k | 70.10k | 2.04 MB/sec | 11.57 MB/sec | **6.43X** |
29
+ | routing/lot-of-routes.js | /999 | 4.66k | 51.58k | 0.85 MB/sec | 8.07 MB/sec | **11.07X** |
30
+ | routing/some-middlewares.js | /90 | 10.18k | 66.97k | 1.81 MB/sec | 10.42 MB/sec | **6.58X** |
31
+ | middlewares/express-static | /static/index.js | 7.52k | 31.08k | 6.92 MB/sec | 26.48 MB/sec | **4.13X** |
32
+ | engines/ejs.js | /test | 5.92k | 14.43k | 2.40 MB/sec | 5.53 MB/sec | **2.44X** |
33
+ | middlewares/body-urlencoded | /abc (POST) | 7.90k | 29.90k | 1.64 MB/sec | 5.36 MB/sec | **3.78X** |
34
+
35
+ Also tested on a real-world application with templates, static files and dynamic pages with data from database ([nekoweb.org](https://nekoweb.org)), and showed about 1.5-4X speedup in requests per second.
36
+
22
37
  ## Differences from Express
23
38
 
24
39
  In a lot of cases, you can just replace `require("express")` with `require("ultimate-express")` and everything works the same. But there are some differences:
@@ -81,6 +96,8 @@ Optimized routes can be up to 10 times faster than normal routes, as they're usi
81
96
 
82
97
  ## Compatibility
83
98
 
99
+ In general, basically all features and options are supported. Use [Express 4.x documentation](https://expressjs.com/en/4x/api.html) for API reference.
100
+
84
101
  ✅ - Full support (all features and options are supported)
85
102
  🚧 - Partial support (some options are not supported)
86
103
  ❌ - Not supported
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "test": "node tests/index.js"
8
8
  },
9
+ "files": [
10
+ "src",
11
+ "EXPRESS_LICENSE"
12
+ ],
9
13
  "repository": {
10
14
  "type": "git",
11
- "url": "git+https://github.com/dimdenGD/u-express.git"
15
+ "url": "git+https://github.com/dimdenGD/ultimate-express.git"
12
16
  },
13
17
  "keywords": [
14
18
  "express",
@@ -27,17 +31,15 @@
27
31
  "author": "dimden.dev",
28
32
  "license": "Apache-2.0",
29
33
  "bugs": {
30
- "url": "https://github.com/dimdenGD/u-express/issues"
34
+ "url": "https://github.com/dimdenGD/ultimate-express/issues"
31
35
  },
32
- "homepage": "https://github.com/dimdenGD/u-express#readme",
36
+ "homepage": "https://github.com/dimdenGD/ultimate-express#readme",
33
37
  "dependencies": {
34
38
  "accepts": "^1.3.8",
35
39
  "body-parser": "^1.20.3",
36
40
  "cookie": "^0.6.0",
37
- "cookie-session": "^2.1.0",
38
41
  "cookie-signature": "^1.2.1",
39
42
  "etag": "^1.8.1",
40
- "express-rate-limit": "^7.4.0",
41
43
  "fresh": "^0.5.2",
42
44
  "mime-types": "^2.1.35",
43
45
  "ms": "^2.1.3",
@@ -52,6 +54,7 @@
52
54
  },
53
55
  "devDependencies": {
54
56
  "cookie-parser": "^1.4.6",
57
+ "cookie-session": "^2.1.0",
55
58
  "cors": "^2.8.5",
56
59
  "ejs": "^3.1.10",
57
60
  "errorhandler": "^1.5.1",
@@ -61,6 +64,7 @@
61
64
  "express-dot-engine": "^1.0.8",
62
65
  "express-fileupload": "^1.5.1",
63
66
  "express-handlebars": "^8.0.1",
67
+ "express-rate-limit": "^7.4.0",
64
68
  "express-session": "^1.18.0",
65
69
  "method-override": "^3.0.0",
66
70
  "multer": "^1.4.5-lts.1",
package/src/request.js CHANGED
@@ -46,7 +46,7 @@ module.exports = class Request extends Readable {
46
46
  this._gotParams = new Set();
47
47
  this._stack = [];
48
48
  this._paramStack = [];
49
- this.bufferedData = Buffer.alloc(0);
49
+ this.bufferedData = Buffer.allocUnsafe(0);
50
50
  this.receivedData = false;
51
51
 
52
52
  const additionalMethods = this.app.get('body methods');
package/src/router.js CHANGED
@@ -52,10 +52,11 @@ module.exports = class Router extends EventEmitter {
52
52
  get(path, ...callbacks) {
53
53
  if(typeof path === 'string' && callbacks.length === 0) {
54
54
  const key = path;
55
- if(typeof this.settings[key] === 'undefined' && this.parent) {
55
+ const res = this.settings[key];
56
+ if(typeof res === 'undefined' && this.parent) {
56
57
  return this.parent.get(key);
57
58
  } else {
58
- return this.settings[key];
59
+ return res;
59
60
  }
60
61
  }
61
62
  return this.#createRoute('GET', path, this, ...callbacks);
@@ -419,7 +420,12 @@ module.exports = class Router extends EventEmitter {
419
420
  if(!skipCheck && skipUntil && skipUntil.routeKey >= route.routeKey) {
420
421
  return next();
421
422
  }
422
- await callback(req, res, next);
423
+ const out = callback(req, res, next);
424
+ if(out instanceof Promise) {
425
+ out.catch(err => {
426
+ throw err;
427
+ });
428
+ }
423
429
  } catch(err) {
424
430
  this.#handleError(err, req, res);
425
431
  return resolve(true);
package/src/utils.js CHANGED
@@ -13,7 +13,7 @@ function patternToRegex(pattern, isPrefix = false) {
13
13
  if(pattern instanceof RegExp) {
14
14
  return pattern;
15
15
  }
16
- if(isPrefix && pattern === '/') {
16
+ if(isPrefix && pattern === '') {
17
17
  return new RegExp(``);
18
18
  }
19
19
 
@@ -241,7 +241,10 @@ function isPreconditionFailure(req, res) {
241
241
 
242
242
  function createETagGenerator(options) {
243
243
  return function generateETag (body, encoding) {
244
- const buf = !(body instanceof Stats) && !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
244
+ if(body instanceof Stats) {
245
+ return etag(body, options);
246
+ }
247
+ const buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
245
248
  return etag(buf, options);
246
249
  }
247
250
  }
@@ -1,27 +0,0 @@
1
- name: Run tests
2
-
3
- on:
4
- push:
5
- branches: [ "main" ]
6
- pull_request:
7
- branches: [ "main" ]
8
-
9
- jobs:
10
- test:
11
-
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - name: Checkout Source Tree
16
- uses: actions/checkout@v3
17
-
18
- - name: Setup Node.js environment
19
- uses: actions/setup-node@v4
20
- with:
21
- node-version: 20
22
-
23
- - name: Install dependencies
24
- run: npm install --include=dev
25
-
26
- - name: Run tests
27
- run: npm run test
package/tests/index.js DELETED
@@ -1,64 +0,0 @@
1
- // npm run test - runs all tests
2
- // npm run test routing - runs all tests in the routing category
3
- // npm run test tests/tests/routing - runs all tests in the routing category
4
- // npm run test tests/tests/listen/listen-random.js - runs the test at tests/tests/listen/listen-random.js
5
-
6
- const fs = require("fs");
7
- const path = require("path");
8
- const test = require("node:test");
9
- const childProcess = require("node:child_process");
10
- const assert = require("node:assert");
11
-
12
- const testPath = path.join(__dirname, 'tests');
13
-
14
- let testCategories = fs.readdirSync(testPath).sort((a, b) => parseInt(a) - parseInt(b));
15
- const filterPath = process.argv[2];
16
-
17
- if(filterPath) {
18
- if(!filterPath.endsWith('.js')) {
19
- testCategories = testCategories.filter(category => category.startsWith(path.basename(filterPath)));
20
- } else {
21
- testCategories = [path.dirname(filterPath).split(path.sep).pop()];
22
- }
23
- }
24
-
25
- for (const testCategory of testCategories) {
26
- test(testCategory, async () => {
27
- let tests = fs.readdirSync(path.join(__dirname, 'tests', testCategory)).sort((a, b) => parseInt(a) - parseInt(b));
28
- for (const testName of tests) {
29
- if(filterPath && filterPath.endsWith('.js')) {
30
- if(path.basename(testName) !== path.basename(filterPath)) {
31
- continue;
32
- }
33
- }
34
- let testPath = path.join(__dirname, 'tests', testCategory, testName);
35
- let testCode = fs.readFileSync(testPath, 'utf8').replace(`const express = require("../../../src/index.js");`, 'const express = require("express");');
36
- fs.writeFileSync(testPath, testCode);
37
- let testDescription = testCode.split('\n')[0].slice(2).trim();
38
- if(testDescription.endsWith('OFF')) {
39
- return true;
40
- }
41
-
42
- await new Promise(resolve => {
43
- test(testDescription, () => {
44
- process.stdout.write(testDescription + '...');
45
- try {
46
- let expressOutput = childProcess.execSync(`node ${testPath}`).toString();
47
-
48
- fs.writeFileSync(testPath, testCode.replace(`const express = require("express");`, `const express = require("../../../src/index.js");`));
49
- let uExpressOutput = childProcess.execSync(`node ${testPath}`).toString();
50
-
51
- assert.strictEqual(uExpressOutput, expressOutput);
52
- console.log('\x1b[32mOK\x1b[0m');
53
- } catch (error) {
54
- console.log('\x1b[31mFAIL\x1b[0m');
55
- throw error;
56
- } finally {
57
- fs.writeFileSync(testPath, testCode);
58
- resolve();
59
- }
60
- });
61
- });
62
- }
63
- });
64
- }
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Document</title>
7
- </head>
8
- <body>
9
- test
10
- </body>
11
- </html>
Binary file
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>{{ title }}</title>
7
- </head>
8
- <body>
9
- <h1>{{ message }}</h1>
10
- <span>{{ asdf }}</span>
11
- </body>
12
- </html>
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>[[= title ]]</title>
7
- </head>
8
- <body>
9
- <h1>[[= message ]]</h1>
10
- <span>[[= asdf ]]</span>
11
- </body>
12
- </html>
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title><%= title %></title>
7
- </head>
8
- <body>
9
- <h1><%= message %></h1>
10
- <span><%= asdf %></span>
11
- </body>
12
- </html>
@@ -1,2 +0,0 @@
1
- <h1>{{{ message }}}</h1>
2
- <span>{{{ asdf }}}</span>
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>test</title>
7
- </head>
8
- <body>
9
- <h1>test</h1>
10
- <span>index test</span>
11
- </body>
12
- </html>
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>{{ title }}</title>
7
- </head>
8
- <body>
9
- <h1>{{ message }}</h1>
10
- <span>{{ asdf }}</span>
11
- </body>
12
- </html>
@@ -1,6 +0,0 @@
1
- html
2
- head
3
- title= title
4
- body
5
- h1= message
6
- span= asdf
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>{{ title }}</title>
7
- </head>
8
- <body>
9
- <h1>{{ message }}</h1>
10
- <span>{{ asdf }}</span>
11
- </body>
12
- </html>
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Example App</title>
6
- </head>
7
- <body>
8
-
9
- {{{body}}}
10
-
11
- </body>
12
- </html>
package/tests/preload.cjs DELETED
@@ -1,5 +0,0 @@
1
- let _processExit = process.exit;
2
- process.exit = (...args) => {
3
- console.log('process.exit', ...args);
4
- // _processExit(...args);
5
- };
package/tests/singular.js DELETED
@@ -1,41 +0,0 @@
1
- const childProcess = require("child_process");
2
- const fs = require("fs");
3
- const exitHook = require("exit-hook");
4
- const { exit } = require("process");
5
-
6
- let args = process.argv.slice(2);
7
-
8
- let u = args.some(arg => arg === '-u');
9
- args = args.filter(arg => arg !== '-u');
10
-
11
- let path = args[0];
12
-
13
- if (!path) {
14
- console.error('Usage: node singular.js [-u] <path>');
15
- process.exit(1);
16
- }
17
-
18
- if (u) {
19
- console.log('Running as µExpress');
20
- let code = fs.readFileSync(path, 'utf8');
21
- fs.writeFileSync(path, code.replace('const express = require("express");', 'const express = require("../../../src/index.js");'));
22
- } else {
23
- let code = fs.readFileSync(path, 'utf8');
24
- fs.writeFileSync(path, code.replace(`const express = require("../../../src/index.js");`, `const express = require("express");`));
25
- console.log('Running as normal Express');
26
- }
27
-
28
- let node = childProcess.spawn('node', ['-r', './tests/preload.cjs', path]);
29
-
30
- node.stdout.on('data', data => {
31
- console.log(data.toString());
32
- });
33
-
34
- node.stderr.on('data', data => {
35
- console.error(data.toString());
36
- });
37
-
38
- exitHook(() => {
39
- let code = fs.readFileSync(path, 'utf8');
40
- fs.writeFileSync(path, code.replaceAll(`const express = require("../../../src/index.js");`, `const express = require("express");`));
41
- });
@@ -1,8 +0,0 @@
1
- // must support app.engine()
2
-
3
- const express = require("express");
4
-
5
- const app = express();
6
- app.engine('asdf', function test() {});
7
-
8
- console.log(app.engines);
@@ -1,24 +0,0 @@
1
- // must emit 'mount' when using subapp
2
-
3
- const express = require("express");
4
-
5
- const app = express();
6
- const student = express();
7
- const teacher = express();
8
-
9
- teacher.on('mount', (parent) => {
10
- console.log('aaaaaaaaaaaaaaaaaaaaaaaaaa');
11
- });
12
-
13
- student.on('mount', (parent) => {
14
- console.log('dewd');
15
- });
16
-
17
- app.use('/student', student);
18
- app.use('/teacher', teacher);
19
-
20
- app.listen(13333, (err) => {
21
- console.log("Server is running on port 13333");
22
-
23
- process.exit(0);
24
- });
@@ -1,21 +0,0 @@
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);
@@ -1,30 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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'));
@@ -1,16 +0,0 @@
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
-
@@ -1,33 +0,0 @@
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
- });
@@ -1,28 +0,0 @@
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
- });
@@ -1,25 +0,0 @@
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
- });
@@ -1,28 +0,0 @@
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
- });