@webqit/webflo 0.11.21 → 0.11.24
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/.gitignore +7 -7
- package/LICENSE +20 -20
- package/README.md +2074 -2071
- package/package.json +82 -82
- package/src/Context.js +79 -79
- package/src/config-pi/deployment/Env.js +69 -69
- package/src/config-pi/deployment/Layout.js +65 -65
- package/src/config-pi/deployment/Origins.js +133 -133
- package/src/config-pi/deployment/Virtualization.js +65 -65
- package/src/config-pi/deployment/index.js +17 -17
- package/src/config-pi/index.js +15 -15
- package/src/config-pi/runtime/Client.js +101 -101
- package/src/config-pi/runtime/Server.js +128 -128
- package/src/config-pi/runtime/client/Worker.js +135 -135
- package/src/config-pi/runtime/client/index.js +11 -11
- package/src/config-pi/runtime/index.js +17 -17
- package/src/config-pi/runtime/server/Headers.js +77 -77
- package/src/config-pi/runtime/server/Redirects.js +73 -73
- package/src/config-pi/runtime/server/index.js +13 -13
- package/src/config-pi/static/Manifest.js +321 -321
- package/src/config-pi/static/Ssg.js +51 -51
- package/src/config-pi/static/index.js +13 -13
- package/src/deployment-pi/index.js +10 -10
- package/src/deployment-pi/origins/index.js +215 -215
- package/src/index.js +19 -19
- package/src/runtime-pi/Router.js +131 -131
- package/src/runtime-pi/client/Context.js +6 -6
- package/src/runtime-pi/client/Router.js +47 -47
- package/src/runtime-pi/client/Runtime.js +357 -341
- package/src/runtime-pi/client/RuntimeClient.js +98 -98
- package/src/runtime-pi/client/Storage.js +56 -56
- package/src/runtime-pi/client/Url.js +205 -205
- package/src/runtime-pi/client/Workport.js +163 -163
- package/src/runtime-pi/client/generate.js +467 -467
- package/src/runtime-pi/client/index.js +23 -23
- package/src/runtime-pi/client/oohtml/full.js +6 -6
- package/src/runtime-pi/client/oohtml/namespacing.js +6 -6
- package/src/runtime-pi/client/oohtml/scripting.js +7 -7
- package/src/runtime-pi/client/oohtml/templating.js +7 -7
- package/src/runtime-pi/client/whatwag.js +27 -27
- package/src/runtime-pi/client/worker/Context.js +6 -6
- package/src/runtime-pi/client/worker/Worker.js +291 -291
- package/src/runtime-pi/client/worker/WorkerClient.js +46 -46
- package/src/runtime-pi/client/worker/Workport.js +79 -79
- package/src/runtime-pi/client/worker/index.js +23 -23
- package/src/runtime-pi/index.js +13 -13
- package/src/runtime-pi/server/Context.js +15 -15
- package/src/runtime-pi/server/Router.js +157 -157
- package/src/runtime-pi/server/Runtime.js +547 -547
- package/src/runtime-pi/server/RuntimeClient.js +112 -112
- package/src/runtime-pi/server/index.js +23 -23
- package/src/runtime-pi/server/whatwag.js +35 -35
- package/src/runtime-pi/util.js +162 -162
- package/src/runtime-pi/xFormData.js +59 -59
- package/src/runtime-pi/xHeaders.js +87 -87
- package/src/runtime-pi/xHttpEvent.js +92 -92
- package/src/runtime-pi/xHttpMessage.js +179 -179
- package/src/runtime-pi/xRequest.js +73 -73
- package/src/runtime-pi/xRequestHeaders.js +94 -94
- package/src/runtime-pi/xResponse.js +68 -68
- package/src/runtime-pi/xResponseHeaders.js +109 -109
- package/src/runtime-pi/xURL.js +110 -110
- package/src/runtime-pi/xfetch.js +6 -6
- package/src/services-pi/certbot/http-auth-hook.js +22 -22
- package/src/services-pi/certbot/http-cleanup-hook.js +22 -22
- package/src/services-pi/certbot/index.js +79 -79
- package/src/services-pi/index.js +8 -8
- package/src/static-pi/index.js +10 -10
- package/src/webflo.js +31 -31
- package/test/index.test.js +26 -25
- package/test/site/package.json +9 -9
- package/test/site/public/bundle.html +5 -5
- package/test/site/public/bundle.html.json +3 -3
- package/test/site/public/bundle.js +2 -2
- package/test/site/public/bundle.webflo.js +15 -15
- package/test/site/public/index.html +29 -29
- package/test/site/public/index1.html +34 -34
- package/test/site/public/page-2/bundle.html +4 -4
- package/test/site/public/page-2/bundle.js +2 -2
- package/test/site/public/page-2/index.html +45 -45
- package/test/site/public/page-2/main.html +2 -2
- package/test/site/public/page-4/subpage/bundle.js +2 -2
- package/test/site/public/page-4/subpage/index.html +30 -30
- package/test/site/public/sparoots.json +4 -4
- package/test/site/public/worker.js +3 -3
- package/test/site/server/index.js +15 -15
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* imports
|
|
4
|
-
*/
|
|
5
|
-
import Fs from 'fs';
|
|
6
|
-
import Path from 'path';
|
|
7
|
-
import QueryString from 'querystring';
|
|
8
|
-
import Router from './Router.js';
|
|
9
|
-
|
|
10
|
-
export default class RuntimeClient {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* RuntimeClient
|
|
14
|
-
*
|
|
15
|
-
* @param Context cx
|
|
16
|
-
*/
|
|
17
|
-
constructor(cx) {
|
|
18
|
-
this.cx = cx;
|
|
19
|
-
this.renderFileCache = {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Handles navigation events.
|
|
24
|
-
*
|
|
25
|
-
* @param NavigationEvent httpEvent
|
|
26
|
-
* @param Function remoteFetch
|
|
27
|
-
*
|
|
28
|
-
* @return Response
|
|
29
|
-
*/
|
|
30
|
-
async handle(httpEvent, remoteFetch) {
|
|
31
|
-
// The app router
|
|
32
|
-
const router = new Router(this.cx, httpEvent.url.pathname);
|
|
33
|
-
const handle = async () => {
|
|
34
|
-
// --------
|
|
35
|
-
// ROUTE FOR DATA
|
|
36
|
-
// --------
|
|
37
|
-
let httpMethodName = httpEvent.request.method.toLowerCase();
|
|
38
|
-
let response = await router.route([httpMethodName === 'delete' ? 'del' : httpMethodName, 'default'], httpEvent, {}, async event => {
|
|
39
|
-
return router.file(event);
|
|
40
|
-
}, remoteFetch);
|
|
41
|
-
if (!(response instanceof httpEvent.Response)) {
|
|
42
|
-
response = new httpEvent.Response(response);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// --------
|
|
46
|
-
// Rendering
|
|
47
|
-
// --------
|
|
48
|
-
|
|
49
|
-
if (response.ok && response.bodyAttrs.inputType === 'object' && httpEvent.request.headers.accept.match('text/html')) {
|
|
50
|
-
let rendering = await this.render(httpEvent, router, response);
|
|
51
|
-
if (typeof rendering !== 'string' && !(typeof rendering === 'object' && rendering && typeof rendering.toString === 'function')) {
|
|
52
|
-
throw new Error('render() must return a string response or an object that implements toString()..');
|
|
53
|
-
}
|
|
54
|
-
response = new httpEvent.Response(rendering.toString(), {
|
|
55
|
-
status: response.status,
|
|
56
|
-
headers: { ...response.headers.json(), contentType: 'text/html' },
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return response;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// --------
|
|
64
|
-
// PIPE THROUGH MIDDLEWARES
|
|
65
|
-
// --------
|
|
66
|
-
return (this.cx.middlewares || []).concat(handle).reverse().reduce((next, fn) => {
|
|
67
|
-
return () => fn.call(this.cx, httpEvent, router, next);
|
|
68
|
-
}, null)();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Renderer
|
|
72
|
-
async render(httpEvent, router, response) {
|
|
73
|
-
let data = await response.json();
|
|
74
|
-
let rendering = await router.route('render', httpEvent, data, async (httpEvent, data) => {
|
|
75
|
-
var renderFile, pathnameSplit = httpEvent.url.pathname.split('/');
|
|
76
|
-
while ((renderFile = Path.join(this.cx.CWD, this.cx.layout.PUBLIC_DIR, './' + pathnameSplit.join('/'), 'index.html'))
|
|
77
|
-
&& (this.renderFileCache[renderFile] === false/* false on previous runs */ || !Fs.existsSync(renderFile))) {
|
|
78
|
-
this.renderFileCache[renderFile] = false;
|
|
79
|
-
pathnameSplit.pop();
|
|
80
|
-
}
|
|
81
|
-
const instanceParams = QueryString.stringify({
|
|
82
|
-
file: renderFile,
|
|
83
|
-
url: httpEvent.url.href,
|
|
84
|
-
root: this.cx.CWD,
|
|
85
|
-
oohtml_level: this.cx.server.oohtml_support,
|
|
86
|
-
});
|
|
87
|
-
const { window } = await import('@webqit/oohtml-ssr/instance.js?' + instanceParams);
|
|
88
|
-
// --------
|
|
89
|
-
// OOHTML would waiting for DOM-ready in order to be initialized
|
|
90
|
-
if (window.WebQit.DOM) {
|
|
91
|
-
await new Promise(res => window.WebQit.DOM.ready(res));
|
|
92
|
-
}
|
|
93
|
-
if (window.document.templates) {
|
|
94
|
-
await new Promise(res => (window.document.templatesReadyState === 'complete' && res(), window.document.addEventListener('templatesreadystatechange', res)));
|
|
95
|
-
}
|
|
96
|
-
if (window.document.state) {
|
|
97
|
-
if (!window.document.state.env) {
|
|
98
|
-
window.document.setState({
|
|
99
|
-
env: 'server',
|
|
100
|
-
}, { update: true });
|
|
101
|
-
}
|
|
102
|
-
window.document.setState({ data, url: httpEvent.url }, { update: 'merge' });
|
|
103
|
-
}
|
|
104
|
-
if (window.document.templates) {
|
|
105
|
-
window.document.body.setAttribute('template', 'routes/' + httpEvent.url.pathname.split('/').filter(a => a).map(a => a + '+-').join('/'));
|
|
106
|
-
}
|
|
107
|
-
await new Promise(res => setTimeout(res, 10));
|
|
108
|
-
return window;
|
|
109
|
-
});
|
|
110
|
-
return rendering + '';
|
|
111
|
-
}
|
|
112
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* imports
|
|
4
|
+
*/
|
|
5
|
+
import Fs from 'fs';
|
|
6
|
+
import Path from 'path';
|
|
7
|
+
import QueryString from 'querystring';
|
|
8
|
+
import Router from './Router.js';
|
|
9
|
+
|
|
10
|
+
export default class RuntimeClient {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RuntimeClient
|
|
14
|
+
*
|
|
15
|
+
* @param Context cx
|
|
16
|
+
*/
|
|
17
|
+
constructor(cx) {
|
|
18
|
+
this.cx = cx;
|
|
19
|
+
this.renderFileCache = {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Handles navigation events.
|
|
24
|
+
*
|
|
25
|
+
* @param NavigationEvent httpEvent
|
|
26
|
+
* @param Function remoteFetch
|
|
27
|
+
*
|
|
28
|
+
* @return Response
|
|
29
|
+
*/
|
|
30
|
+
async handle(httpEvent, remoteFetch) {
|
|
31
|
+
// The app router
|
|
32
|
+
const router = new Router(this.cx, httpEvent.url.pathname);
|
|
33
|
+
const handle = async () => {
|
|
34
|
+
// --------
|
|
35
|
+
// ROUTE FOR DATA
|
|
36
|
+
// --------
|
|
37
|
+
let httpMethodName = httpEvent.request.method.toLowerCase();
|
|
38
|
+
let response = await router.route([httpMethodName === 'delete' ? 'del' : httpMethodName, 'default'], httpEvent, {}, async event => {
|
|
39
|
+
return router.file(event);
|
|
40
|
+
}, remoteFetch);
|
|
41
|
+
if (!(response instanceof httpEvent.Response)) {
|
|
42
|
+
response = new httpEvent.Response(response);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// --------
|
|
46
|
+
// Rendering
|
|
47
|
+
// --------
|
|
48
|
+
|
|
49
|
+
if (response.ok && response.bodyAttrs.inputType === 'object' && httpEvent.request.headers.accept.match('text/html')) {
|
|
50
|
+
let rendering = await this.render(httpEvent, router, response);
|
|
51
|
+
if (typeof rendering !== 'string' && !(typeof rendering === 'object' && rendering && typeof rendering.toString === 'function')) {
|
|
52
|
+
throw new Error('render() must return a string response or an object that implements toString()..');
|
|
53
|
+
}
|
|
54
|
+
response = new httpEvent.Response(rendering.toString(), {
|
|
55
|
+
status: response.status,
|
|
56
|
+
headers: { ...response.headers.json(), contentType: 'text/html' },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return response;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// --------
|
|
64
|
+
// PIPE THROUGH MIDDLEWARES
|
|
65
|
+
// --------
|
|
66
|
+
return (this.cx.middlewares || []).concat(handle).reverse().reduce((next, fn) => {
|
|
67
|
+
return () => fn.call(this.cx, httpEvent, router, next);
|
|
68
|
+
}, null)();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Renderer
|
|
72
|
+
async render(httpEvent, router, response) {
|
|
73
|
+
let data = await response.json();
|
|
74
|
+
let rendering = await router.route('render', httpEvent, data, async (httpEvent, data) => {
|
|
75
|
+
var renderFile, pathnameSplit = httpEvent.url.pathname.split('/');
|
|
76
|
+
while ((renderFile = Path.join(this.cx.CWD, this.cx.layout.PUBLIC_DIR, './' + pathnameSplit.join('/'), 'index.html'))
|
|
77
|
+
&& (this.renderFileCache[renderFile] === false/* false on previous runs */ || !Fs.existsSync(renderFile))) {
|
|
78
|
+
this.renderFileCache[renderFile] = false;
|
|
79
|
+
pathnameSplit.pop();
|
|
80
|
+
}
|
|
81
|
+
const instanceParams = QueryString.stringify({
|
|
82
|
+
file: renderFile,
|
|
83
|
+
url: httpEvent.url.href,
|
|
84
|
+
root: this.cx.CWD,
|
|
85
|
+
oohtml_level: this.cx.server.oohtml_support,
|
|
86
|
+
});
|
|
87
|
+
const { window } = await import('@webqit/oohtml-ssr/instance.js?' + instanceParams);
|
|
88
|
+
// --------
|
|
89
|
+
// OOHTML would waiting for DOM-ready in order to be initialized
|
|
90
|
+
if (window.WebQit.DOM) {
|
|
91
|
+
await new Promise(res => window.WebQit.DOM.ready(res));
|
|
92
|
+
}
|
|
93
|
+
if (window.document.templates) {
|
|
94
|
+
await new Promise(res => (window.document.templatesReadyState === 'complete' && res(), window.document.addEventListener('templatesreadystatechange', res)));
|
|
95
|
+
}
|
|
96
|
+
if (window.document.state) {
|
|
97
|
+
if (!window.document.state.env) {
|
|
98
|
+
window.document.setState({
|
|
99
|
+
env: 'server',
|
|
100
|
+
}, { update: true });
|
|
101
|
+
}
|
|
102
|
+
window.document.setState({ data, url: httpEvent.url }, { update: 'merge' });
|
|
103
|
+
}
|
|
104
|
+
if (window.document.templates) {
|
|
105
|
+
window.document.body.setAttribute('template', 'routes/' + httpEvent.url.pathname.split('/').filter(a => a).map(a => a + '+-').join('/'));
|
|
106
|
+
}
|
|
107
|
+
await new Promise(res => setTimeout(res, 10));
|
|
108
|
+
return window;
|
|
109
|
+
});
|
|
110
|
+
return rendering + '';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
113
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import Context from './Context.js';
|
|
6
|
-
import RuntimeClient from './RuntimeClient.js';
|
|
7
|
-
import Runtime from './Runtime.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @start
|
|
11
|
-
*/
|
|
12
|
-
export async function start(clientCallback = null) {
|
|
13
|
-
const cx = this || {};
|
|
14
|
-
const defaultClientCallback = _cx => new RuntimeClient(_cx);
|
|
15
|
-
return new Runtime(Context.create(cx), ( ...args ) => {
|
|
16
|
-
return clientCallback ? clientCallback( ...args.concat( defaultClientCallback ) ) : defaultClientCallback( ...args );
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @APIS
|
|
22
|
-
*/
|
|
23
|
-
export * as APIS from './Runtime.js';
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import Context from './Context.js';
|
|
6
|
+
import RuntimeClient from './RuntimeClient.js';
|
|
7
|
+
import Runtime from './Runtime.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @start
|
|
11
|
+
*/
|
|
12
|
+
export async function start(clientCallback = null) {
|
|
13
|
+
const cx = this || {};
|
|
14
|
+
const defaultClientCallback = _cx => new RuntimeClient(_cx);
|
|
15
|
+
return new Runtime(Context.create(cx), ( ...args ) => {
|
|
16
|
+
return clientCallback ? clientCallback( ...args.concat( defaultClientCallback ) ) : defaultClientCallback( ...args );
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @APIS
|
|
22
|
+
*/
|
|
23
|
+
export * as APIS from './Runtime.js';
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { URL } from 'url';
|
|
6
|
-
import { FormData, File, Blob } from 'formdata-node';
|
|
7
|
-
import fetch, { Request, Response, Headers } from 'node-fetch';
|
|
8
|
-
import { FormDataEncoder } from 'form-data-encoder';
|
|
9
|
-
import { Readable } from "stream";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The NavigationEvent class
|
|
13
|
-
*/
|
|
14
|
-
if (!Request.prototype.formData) {
|
|
15
|
-
Request.prototype.formData = async function() { return null }
|
|
16
|
-
}
|
|
17
|
-
if (!Response.prototype.formData) {
|
|
18
|
-
Response.prototype.formData = async function() { return null }
|
|
19
|
-
}
|
|
20
|
-
FormData.encode = formData => {
|
|
21
|
-
const encoder = new FormDataEncoder(formData);
|
|
22
|
-
return [ Readable.from(encoder.encode()), encoder.headers ];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
URL,
|
|
27
|
-
fetch,
|
|
28
|
-
Headers,
|
|
29
|
-
Request,
|
|
30
|
-
Response,
|
|
31
|
-
FormData,
|
|
32
|
-
Readable as ReadableStream,
|
|
33
|
-
File,
|
|
34
|
-
Blob,
|
|
35
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { URL } from 'url';
|
|
6
|
+
import { FormData, File, Blob } from 'formdata-node';
|
|
7
|
+
import fetch, { Request, Response, Headers } from 'node-fetch';
|
|
8
|
+
import { FormDataEncoder } from 'form-data-encoder';
|
|
9
|
+
import { Readable } from "stream";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The NavigationEvent class
|
|
13
|
+
*/
|
|
14
|
+
if (!Request.prototype.formData) {
|
|
15
|
+
Request.prototype.formData = async function() { return null }
|
|
16
|
+
}
|
|
17
|
+
if (!Response.prototype.formData) {
|
|
18
|
+
Response.prototype.formData = async function() { return null }
|
|
19
|
+
}
|
|
20
|
+
FormData.encode = formData => {
|
|
21
|
+
const encoder = new FormDataEncoder(formData);
|
|
22
|
+
return [ Readable.from(encoder.encode()), encoder.headers ];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
URL,
|
|
27
|
+
fetch,
|
|
28
|
+
Headers,
|
|
29
|
+
Request,
|
|
30
|
+
Response,
|
|
31
|
+
FormData,
|
|
32
|
+
Readable as ReadableStream,
|
|
33
|
+
File,
|
|
34
|
+
Blob,
|
|
35
|
+
}
|