@webqit/webflo 0.11.60 → 0.11.61

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 (91) hide show
  1. package/.gitignore +7 -7
  2. package/LICENSE +20 -20
  3. package/README.md +2079 -2074
  4. package/docker/Dockerfile +42 -42
  5. package/docker/README.md +91 -91
  6. package/docker/package.json +2 -2
  7. package/package.json +80 -81
  8. package/src/Context.js +79 -79
  9. package/src/config-pi/deployment/Env.js +68 -68
  10. package/src/config-pi/deployment/Layout.js +63 -63
  11. package/src/config-pi/deployment/Origins.js +139 -139
  12. package/src/config-pi/deployment/Proxy.js +74 -74
  13. package/src/config-pi/deployment/index.js +17 -17
  14. package/src/config-pi/index.js +15 -15
  15. package/src/config-pi/runtime/Client.js +116 -98
  16. package/src/config-pi/runtime/Server.js +125 -125
  17. package/src/config-pi/runtime/client/Worker.js +109 -134
  18. package/src/config-pi/runtime/client/index.js +11 -11
  19. package/src/config-pi/runtime/index.js +17 -17
  20. package/src/config-pi/runtime/server/Headers.js +74 -74
  21. package/src/config-pi/runtime/server/Redirects.js +69 -69
  22. package/src/config-pi/runtime/server/index.js +13 -13
  23. package/src/config-pi/static/Manifest.js +319 -319
  24. package/src/config-pi/static/Ssg.js +49 -49
  25. package/src/config-pi/static/index.js +13 -13
  26. package/src/deployment-pi/index.js +10 -10
  27. package/src/deployment-pi/origins/index.js +216 -216
  28. package/src/index.js +19 -19
  29. package/src/runtime-pi/Application.js +28 -28
  30. package/src/runtime-pi/Cookies.js +81 -81
  31. package/src/runtime-pi/HttpEvent.js +106 -106
  32. package/src/runtime-pi/Router.js +130 -130
  33. package/src/runtime-pi/Runtime.js +20 -20
  34. package/src/runtime-pi/client/Application.js +76 -100
  35. package/src/runtime-pi/client/Context.js +7 -7
  36. package/src/runtime-pi/client/Router.js +48 -48
  37. package/src/runtime-pi/client/Runtime.js +524 -331
  38. package/src/runtime-pi/client/Url.js +204 -205
  39. package/src/runtime-pi/client/Workport.js +190 -178
  40. package/src/runtime-pi/client/createStorage.js +57 -56
  41. package/src/runtime-pi/client/generate.js +480 -471
  42. package/src/runtime-pi/client/index.js +21 -21
  43. package/src/runtime-pi/client/worker/Application.js +44 -44
  44. package/src/runtime-pi/client/worker/Context.js +7 -7
  45. package/src/runtime-pi/client/worker/Runtime.js +274 -268
  46. package/src/runtime-pi/client/worker/Workport.js +77 -89
  47. package/src/runtime-pi/client/worker/index.js +21 -21
  48. package/src/runtime-pi/index.js +13 -13
  49. package/src/runtime-pi/server/Application.js +100 -115
  50. package/src/runtime-pi/server/Context.js +15 -15
  51. package/src/runtime-pi/server/Router.js +159 -159
  52. package/src/runtime-pi/server/Runtime.js +557 -556
  53. package/src/runtime-pi/server/index.js +21 -21
  54. package/src/runtime-pi/util-http.js +85 -85
  55. package/src/runtime-pi/util-url.js +146 -146
  56. package/src/runtime-pi/xFormData.js +23 -23
  57. package/src/runtime-pi/xHeaders.js +145 -145
  58. package/src/runtime-pi/xRequest.js +45 -45
  59. package/src/runtime-pi/xRequestHeaders.js +108 -108
  60. package/src/runtime-pi/xResponse.js +32 -32
  61. package/src/runtime-pi/xResponseHeaders.js +116 -116
  62. package/src/runtime-pi/xURL.js +105 -105
  63. package/src/runtime-pi/xfetch.js +22 -22
  64. package/src/runtime-pi/xxHttpMessage.js +101 -101
  65. package/src/services-pi/cert/http-auth-hook.js +22 -22
  66. package/src/services-pi/cert/http-cleanup-hook.js +22 -22
  67. package/src/services-pi/cert/index.js +79 -79
  68. package/src/services-pi/index.js +8 -8
  69. package/src/static-pi/index.js +10 -10
  70. package/src/webflo.js +30 -30
  71. package/test/index.test.js +26 -26
  72. package/test/site/package.json +9 -9
  73. package/test/site/public/bundle.html +5 -5
  74. package/test/site/public/bundle.html.json +3 -3
  75. package/test/site/public/bundle.js +2 -2
  76. package/test/site/public/bundle.webflo.js +15 -15
  77. package/test/site/public/index.html +29 -29
  78. package/test/site/public/index1.html +34 -34
  79. package/test/site/public/page-2/bundle.html +4 -4
  80. package/test/site/public/page-2/bundle.js +2 -2
  81. package/test/site/public/page-2/index.html +45 -45
  82. package/test/site/public/page-2/main.html +2 -2
  83. package/test/site/public/page-4/subpage/bundle.js +2 -2
  84. package/test/site/public/page-4/subpage/index.html +30 -30
  85. package/test/site/public/sparoots.json +4 -4
  86. package/test/site/public/worker.js +3 -3
  87. package/test/site/server/index.js +15 -15
  88. package/src/runtime-pi/client/oohtml/full.js +0 -7
  89. package/src/runtime-pi/client/oohtml/namespacing.js +0 -7
  90. package/src/runtime-pi/client/oohtml/scripting.js +0 -8
  91. package/src/runtime-pi/client/oohtml/templating.js +0 -8
@@ -1,159 +1,159 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import Fs from 'fs';
6
- import Url from 'url';
7
- import Path from 'path';
8
- import Mime from 'mime-types';
9
- import _Router from '../Router.js';
10
-
11
- /**
12
- * ---------------------------
13
- * The Router class
14
- * ---------------------------
15
- */
16
-
17
- export default class Router extends _Router {
18
-
19
- async readTick(thisTick) {
20
- thisTick = { ...thisTick };
21
- if (thisTick.trail) {
22
- thisTick.currentSegment = thisTick.destination[thisTick.trail.length];
23
- thisTick.currentSegmentOnFile = [ thisTick.currentSegment, '-' ].reduce((_segmentOnFile, _seg) => {
24
- if (_segmentOnFile.index) return _segmentOnFile;
25
- var _currentPath = thisTick.trailOnFile.concat(_seg).join('/'),
26
- routeHandlerFile;
27
- return Fs.existsSync(routeHandlerFile = Path.join(this.cx.CWD, this.cx.layout.SERVER_DIR, _currentPath, 'index.js')) ? { seg: _seg, index: routeHandlerFile } : (
28
- Fs.existsSync(Path.join(this.cx.CWD, this.cx.layout.SERVER_DIR, _currentPath)) ? { seg: _seg, dirExists: true } : _segmentOnFile
29
- );
30
- }, { seg: null });
31
- thisTick.trail = thisTick.trail.concat(thisTick.currentSegment);
32
- thisTick.trailOnFile = thisTick.trailOnFile.concat(thisTick.currentSegmentOnFile.seg);
33
- thisTick.exports = thisTick.currentSegmentOnFile.index ? await import(Url.pathToFileURL(thisTick.currentSegmentOnFile.index)) : undefined;
34
- } else {
35
- thisTick.trail = [];
36
- thisTick.trailOnFile = [];
37
- thisTick.currentSegmentOnFile = { index: Path.join(this.cx.CWD, this.cx.layout.SERVER_DIR, 'index.js') };
38
- thisTick.exports = Fs.existsSync(thisTick.currentSegmentOnFile.index)
39
- ? await import(Url.pathToFileURL(thisTick.currentSegmentOnFile.index))
40
- : null;
41
- }
42
- return thisTick;
43
- }
44
-
45
- finalizeHandlerContext(context, thisTick) {
46
- if (thisTick.currentSegmentOnFile.index) {
47
- context.dirname = Path.dirname(thisTick.currentSegmentOnFile.index);
48
- }
49
- }
50
-
51
- pathJoin(...args) {
52
- return Path.join(...args);
53
- }
54
-
55
- /**
56
- * Reads a static file from the public directory.
57
- *
58
- * @param ServerNavigationEvent httpEvent
59
- *
60
- * @return Promise
61
- */
62
- file(httpEvent) {
63
- let filename = Path.join(this.cx.CWD, this.cx.layout.PUBLIC_DIR, decodeURIComponent(httpEvent.url.pathname));
64
- let index, ext = Path.parse(httpEvent.url.pathname).ext;
65
- // if is a directory search for index file matching the extention
66
- if (!ext && Fs.existsSync(filename) && Fs.lstatSync(filename).isDirectory()) {
67
- ext = '.html';
68
- index = `index${ext}`;
69
- filename = Path.join(filename, index);
70
- }
71
- let enc, acceptEncs = [], supportedEncs = { gzip: '.gz', br: '.br' };
72
- // based on the URL path, extract the file extention. e.g. .js, .doc, ...
73
- // and process encoding
74
- if ((acceptEncs = (httpEvent.request.headers.get('Accept-Encoding') || '').split(',').map(e => e.trim())).length
75
- && (enc = acceptEncs.reduce((prev, _enc) => prev || (Fs.existsSync(filename + supportedEncs[_enc]) && _enc), null))) {
76
- filename = filename + supportedEncs[enc];
77
- } else {
78
- if (!Fs.existsSync(filename)) return;
79
- if (Object.values(supportedEncs).includes(ext)) {
80
- enc = Object.keys(supportedEncs).reduce((prev, _enc) => prev || (supportedEncs[_enc] === ext && _enc), null);
81
- ext = Path.parse(filename.substring(0, filename.length - ext.length)).ext;
82
- }
83
- }
84
-
85
- // read file from file system
86
- return new Promise(resolve => {
87
- Fs.readFile(filename, function(err, data) {
88
- let response;
89
- if (err) {
90
- response = new httpEvent.Response(null, { status: 500, statusText: `Error reading static file: ${filename}` } );
91
- } else {
92
- // if the file is found, set Content-type and send data
93
- let mime = Mime.lookup(ext);
94
- response = new httpEvent.Response(data, { headers: {
95
- contentType: mime === 'application/javascript' ? 'text/javascript' : mime,
96
- contentLength: Buffer.byteLength(data),
97
- } });
98
- if (enc) {
99
- response.headers.set('Content-Encoding', enc);
100
- }
101
- }
102
- response.attrs.filename = filename;
103
- response.attrs.static = true;
104
- response.attrs.index = index;
105
- resolve(response);
106
- });
107
- });
108
- }
109
-
110
- /**
111
- * Writes a file to the public directory.
112
- *
113
- * @param object filename
114
- * @param string content
115
- *
116
- * @return bool
117
- */
118
- putPreRendered(filename, content) {
119
- var _filename = Path.join(this.cx.layout.PUBLIC_DIR, '.', filename);
120
- if (!Path.parse(filename).ext && filename.lastIndexOf('.') < filename.lastIndexOf('/')) {
121
- _filename = Path.join(_filename, '/index.html');
122
- }
123
- var dir = Path.dirname(_filename);
124
- if (!Fs.existsSync(dir)) {
125
- Fs.mkdirSync(dir, {recursive:true});
126
- }
127
- return Fs.writeFileSync(_filename, content);
128
- }
129
-
130
- /**
131
- * Deletes a file from the public directory.
132
- *
133
- * @param object filename
134
- *
135
- * @return bool
136
- */
137
- deletePreRendered(filename) {
138
- return Fs.unlinkSync(filename);
139
- }
140
- };
141
-
142
- // maps file extention to MIME typere
143
- const mimeTypes = {
144
- '.ico': 'image/x-icon',
145
- '.html': 'text/html',
146
- '.js': 'text/javascript',
147
- '.json': 'application/json',
148
- '.css': 'text/css',
149
- '.png': 'image/png',
150
- '.jpeg': 'image/jpeg',
151
- '.jpg': 'image/jpeg',
152
- '.wav': 'audio/wav',
153
- '.mp3': 'audio/mpeg',
154
- '.svg': 'image/svg+xml',
155
- '.pdf': 'application/pdf',
156
- '.doc': 'application/msword'
157
- };
158
-
159
- export { mimeTypes };
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import Fs from 'fs';
6
+ import Url from 'url';
7
+ import Path from 'path';
8
+ import Mime from 'mime-types';
9
+ import _Router from '../Router.js';
10
+
11
+ /**
12
+ * ---------------------------
13
+ * The Router class
14
+ * ---------------------------
15
+ */
16
+
17
+ export default class Router extends _Router {
18
+
19
+ async readTick(thisTick) {
20
+ thisTick = { ...thisTick };
21
+ if (thisTick.trail) {
22
+ thisTick.currentSegment = thisTick.destination[thisTick.trail.length];
23
+ thisTick.currentSegmentOnFile = [ thisTick.currentSegment, '-' ].reduce((_segmentOnFile, _seg) => {
24
+ if (_segmentOnFile.index) return _segmentOnFile;
25
+ var _currentPath = thisTick.trailOnFile.concat(_seg).join('/'),
26
+ routeHandlerFile;
27
+ return Fs.existsSync(routeHandlerFile = Path.join(this.cx.CWD, this.cx.layout.SERVER_DIR, _currentPath, 'index.js')) ? { seg: _seg, index: routeHandlerFile } : (
28
+ Fs.existsSync(Path.join(this.cx.CWD, this.cx.layout.SERVER_DIR, _currentPath)) ? { seg: _seg, dirExists: true } : _segmentOnFile
29
+ );
30
+ }, { seg: null });
31
+ thisTick.trail = thisTick.trail.concat(thisTick.currentSegment);
32
+ thisTick.trailOnFile = thisTick.trailOnFile.concat(thisTick.currentSegmentOnFile.seg);
33
+ thisTick.exports = thisTick.currentSegmentOnFile.index ? await import(Url.pathToFileURL(thisTick.currentSegmentOnFile.index)) : undefined;
34
+ } else {
35
+ thisTick.trail = [];
36
+ thisTick.trailOnFile = [];
37
+ thisTick.currentSegmentOnFile = { index: Path.join(this.cx.CWD, this.cx.layout.SERVER_DIR, 'index.js') };
38
+ thisTick.exports = Fs.existsSync(thisTick.currentSegmentOnFile.index)
39
+ ? await import(Url.pathToFileURL(thisTick.currentSegmentOnFile.index))
40
+ : null;
41
+ }
42
+ return thisTick;
43
+ }
44
+
45
+ finalizeHandlerContext(context, thisTick) {
46
+ if (thisTick.currentSegmentOnFile.index) {
47
+ context.dirname = Path.dirname(thisTick.currentSegmentOnFile.index);
48
+ }
49
+ }
50
+
51
+ pathJoin(...args) {
52
+ return Path.join(...args);
53
+ }
54
+
55
+ /**
56
+ * Reads a static file from the public directory.
57
+ *
58
+ * @param ServerNavigationEvent httpEvent
59
+ *
60
+ * @return Promise
61
+ */
62
+ file(httpEvent) {
63
+ let filename = Path.join(this.cx.CWD, this.cx.layout.PUBLIC_DIR, decodeURIComponent(httpEvent.url.pathname));
64
+ let index, ext = Path.parse(httpEvent.url.pathname).ext;
65
+ // if is a directory search for index file matching the extention
66
+ if (!ext && Fs.existsSync(filename) && Fs.lstatSync(filename).isDirectory()) {
67
+ ext = '.html';
68
+ index = `index${ext}`;
69
+ filename = Path.join(filename, index);
70
+ }
71
+ let enc, acceptEncs = [], supportedEncs = { gzip: '.gz', br: '.br' };
72
+ // based on the URL path, extract the file extention. e.g. .js, .doc, ...
73
+ // and process encoding
74
+ if ((acceptEncs = (httpEvent.request.headers.get('Accept-Encoding') || '').split(',').map(e => e.trim())).length
75
+ && (enc = acceptEncs.reduce((prev, _enc) => prev || (Fs.existsSync(filename + supportedEncs[_enc]) && _enc), null))) {
76
+ filename = filename + supportedEncs[enc];
77
+ } else {
78
+ if (!Fs.existsSync(filename)) return;
79
+ if (Object.values(supportedEncs).includes(ext)) {
80
+ enc = Object.keys(supportedEncs).reduce((prev, _enc) => prev || (supportedEncs[_enc] === ext && _enc), null);
81
+ ext = Path.parse(filename.substring(0, filename.length - ext.length)).ext;
82
+ }
83
+ }
84
+
85
+ // read file from file system
86
+ return new Promise(resolve => {
87
+ Fs.readFile(filename, function(err, data) {
88
+ let response;
89
+ if (err) {
90
+ response = new httpEvent.Response(null, { status: 500, statusText: `Error reading static file: ${filename}` } );
91
+ } else {
92
+ // if the file is found, set Content-type and send data
93
+ let mime = Mime.lookup(ext);
94
+ response = new httpEvent.Response(data, { headers: {
95
+ contentType: mime === 'application/javascript' ? 'text/javascript' : mime,
96
+ contentLength: Buffer.byteLength(data),
97
+ } });
98
+ if (enc) {
99
+ response.headers.set('Content-Encoding', enc);
100
+ }
101
+ }
102
+ response.attrs.filename = filename;
103
+ response.attrs.static = true;
104
+ response.attrs.index = index;
105
+ resolve(response);
106
+ });
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Writes a file to the public directory.
112
+ *
113
+ * @param object filename
114
+ * @param string content
115
+ *
116
+ * @return bool
117
+ */
118
+ putPreRendered(filename, content) {
119
+ var _filename = Path.join(this.cx.layout.PUBLIC_DIR, '.', filename);
120
+ if (!Path.parse(filename).ext && filename.lastIndexOf('.') < filename.lastIndexOf('/')) {
121
+ _filename = Path.join(_filename, '/index.html');
122
+ }
123
+ var dir = Path.dirname(_filename);
124
+ if (!Fs.existsSync(dir)) {
125
+ Fs.mkdirSync(dir, {recursive:true});
126
+ }
127
+ return Fs.writeFileSync(_filename, content);
128
+ }
129
+
130
+ /**
131
+ * Deletes a file from the public directory.
132
+ *
133
+ * @param object filename
134
+ *
135
+ * @return bool
136
+ */
137
+ deletePreRendered(filename) {
138
+ return Fs.unlinkSync(filename);
139
+ }
140
+ };
141
+
142
+ // maps file extention to MIME typere
143
+ const mimeTypes = {
144
+ '.ico': 'image/x-icon',
145
+ '.html': 'text/html',
146
+ '.js': 'text/javascript',
147
+ '.json': 'application/json',
148
+ '.css': 'text/css',
149
+ '.png': 'image/png',
150
+ '.jpeg': 'image/jpeg',
151
+ '.jpg': 'image/jpeg',
152
+ '.wav': 'audio/wav',
153
+ '.mp3': 'audio/mpeg',
154
+ '.svg': 'image/svg+xml',
155
+ '.pdf': 'application/pdf',
156
+ '.doc': 'application/msword'
157
+ };
158
+
159
+ export { mimeTypes };