@underpostnet/underpost 2.7.91 → 2.7.92
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/bin/deploy.js +13 -11
- package/bin/file.js +1 -0
- package/bin/hwt.js +59 -0
- package/bin/index.js +1 -1
- package/conf.js +28 -4
- package/docker-compose.yml +1 -1
- package/package.json +2 -2
- package/src/client/components/core/404.js +20 -0
- package/src/client/components/core/500.js +20 -0
- package/src/client/{ssr/common → components/core}/Alert.js +13 -11
- package/src/client/components/core/Docs.js +1 -1
- package/src/client/components/core/Modal.js +5 -6
- package/src/client/components/core/Translate.js +21 -5
- package/src/client/components/core/VanillaJs.js +2 -1
- package/src/client/components/core/Worker.js +10 -11
- package/src/client/components/default/MenuDefault.js +68 -0
- package/src/client/components/default/RoutesDefault.js +2 -0
- package/src/client/public/default/plantuml/client-conf.svg +1 -1
- package/src/client/public/default/plantuml/client-schema.svg +1 -1
- package/src/client/public/default/plantuml/cron-schema.svg +1 -1
- package/src/client/public/default/plantuml/server-conf.svg +1 -1
- package/src/client/public/default/plantuml/server-schema.svg +1 -1
- package/src/client/public/default/plantuml/ssr-conf.svg +1 -1
- package/src/client/public/default/plantuml/ssr-schema.svg +1 -1
- package/src/client/ssr/Render.js +1 -6
- package/src/client/ssr/{components/body → body}/CacheControl.js +1 -1
- package/src/client/ssr/mailer/DefaultRecoverEmail.js +21 -0
- package/src/client/ssr/mailer/DefaultVerifyEmail.js +17 -0
- package/src/client/ssr/offline/NoNetworkConnection.js +65 -0
- package/src/client/ssr/pages/Test.js +196 -0
- package/src/client/sw/default.sw.js +43 -166
- package/src/mailer/EmailRender.js +2 -4
- package/src/mailer/MailerProvider.js +4 -1
- package/src/server/client-build.js +100 -74
- package/src/server/client-formatted.js +2 -4
- package/src/server/conf.js +40 -13
- package/src/server/proxy.js +0 -2
- package/src/server/runtime.js +38 -10
- package/src/client/ssr/common/SsrCore.js +0 -91
- package/src/client/ssr/common/Translate.js +0 -26
- package/src/client/ssr/common/Worker.js +0 -28
- package/src/client/ssr/components/head/PwaDefault.js +0 -60
- /package/src/client/ssr/{components/body → body}/DefaultSplashScreen.js +0 -0
- /package/src/client/ssr/{components/email → email}/DefaultRecoverEmail.js +0 -0
- /package/src/client/ssr/{components/email → email}/DefaultVerifyEmail.js +0 -0
- /package/src/client/ssr/{components/head → head}/Css.js +0 -0
- /package/src/client/ssr/{components/head → head}/DefaultScripts.js +0 -0
- /package/src/client/ssr/{components/head → head}/Production.js +0 -0
- /package/src/client/ssr/{components/head → head}/Pwa.js +0 -0
- /package/src/client/ssr/{components/head → head}/Seo.js +0 -0
|
@@ -1,58 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// https://googlechrome.github.io/samples/service-worker/custom-offline-page/
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Copyright 2015, 2019 Google Inc. All Rights Reserved.
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
you may not use this file except in compliance with the License.
|
|
9
|
-
You may obtain a copy of the License at
|
|
10
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
See the License for the specific language governing permissions and
|
|
15
|
-
limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
19
|
-
// https://web.dev/cache-api-quick-guide/
|
|
20
|
-
// https://developer.mozilla.org/en-US/docs/Web/API
|
|
21
|
-
// https://developer.mozilla.org/es/docs/Web/Progressive_web_apps/Re-engageable_Notifications_Push
|
|
22
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification
|
|
23
|
-
// https://github.com/GoogleChrome/samples/blob/9e4b3b77b091268d28e5438bb2fe8829091e9540/service-worker/basic/service-worker.js#L59
|
|
24
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
|
|
28
|
-
4 different ways to store data on client-side without using cookies:
|
|
29
|
-
|
|
30
|
-
- Local Storage (Session and Local key/value pairs)
|
|
31
|
-
- Web SQL (my favorite, it's a whole SQL Database, and it's NOT obsolete)
|
|
32
|
-
- IndexedDB (another Database with different structure and acceptance)
|
|
33
|
-
- Service Workers (Persistent background processing,
|
|
34
|
-
even while offline, can asynchronously save files and many other things)
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
const logger = loggerFactory(import.meta);
|
|
39
|
-
|
|
1
|
+
const PRE_CACHED_RESOURCES = [];
|
|
2
|
+
const CACHE_NAME = 'app-cache';
|
|
40
3
|
const PROXY_PATH = '/';
|
|
41
|
-
|
|
42
4
|
self.addEventListener('install', (event) => {
|
|
43
5
|
// Activate right away
|
|
44
6
|
self.skipWaiting();
|
|
45
7
|
|
|
46
8
|
event.waitUntil(
|
|
47
9
|
(async () => {
|
|
48
|
-
// const cache = await caches.open(CACHE_NAME);
|
|
49
|
-
// Setting {cache: 'reload'} in the new request will ensure that the response
|
|
50
|
-
// isn't fulfilled from the HTTP cache; i.e., it will be from the network.
|
|
51
|
-
// await cache.add(new Request(OFFLINE_URL, { cache: 'reload' }));
|
|
52
10
|
// Open the app's cache.
|
|
53
|
-
|
|
11
|
+
const cache = await caches.open(CACHE_NAME);
|
|
54
12
|
// Cache all static resources.
|
|
55
|
-
|
|
13
|
+
try {
|
|
14
|
+
await cache.addAll(PRE_CACHED_RESOURCES);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error(error);
|
|
17
|
+
}
|
|
18
|
+
// for (const cacheKey of PRE_CACHED_RESOURCES) {
|
|
19
|
+
// try {
|
|
20
|
+
// await cache.add(cacheKey);
|
|
21
|
+
// } catch (error) {
|
|
22
|
+
// console.error(error, cacheKey);
|
|
23
|
+
// }
|
|
24
|
+
// }
|
|
56
25
|
})(),
|
|
57
26
|
);
|
|
58
27
|
});
|
|
@@ -67,139 +36,47 @@ self.addEventListener('activate', (event) => {
|
|
|
67
36
|
}
|
|
68
37
|
})(),
|
|
69
38
|
);
|
|
70
|
-
|
|
71
39
|
// Tell the active service worker to take control of the page immediately.
|
|
72
40
|
self.clients.claim();
|
|
73
|
-
|
|
74
|
-
// event message
|
|
75
|
-
self.addEventListener('message', (event) => {
|
|
76
|
-
logger.info('Received event message', event.data);
|
|
77
|
-
|
|
78
|
-
switch (event.data.status) {
|
|
79
|
-
case 'skipWaiting':
|
|
80
|
-
return self.skipWaiting();
|
|
81
|
-
break;
|
|
82
|
-
|
|
83
|
-
default:
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
clients.matchAll().then((clientList) => {
|
|
88
|
-
for (const client of clientList) {
|
|
89
|
-
logger.info('client', client);
|
|
90
|
-
client.postMessage({
|
|
91
|
-
title: 'Hello from SW event message',
|
|
92
|
-
});
|
|
93
|
-
// client -> document.visibilityState
|
|
94
|
-
// client.visibilityState
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
// broadcast message
|
|
99
|
-
const channel = new BroadcastChannel('sw-messages');
|
|
100
|
-
channel.addEventListener('message', (event) => {
|
|
101
|
-
logger.info('Received broadcast message', event.data);
|
|
102
|
-
channel.postMessage({ title: 'Hello from SW broadcast message' });
|
|
103
|
-
});
|
|
104
41
|
});
|
|
105
42
|
|
|
106
43
|
self.addEventListener('fetch', (event) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
(async () => {
|
|
122
|
-
// Get the client.
|
|
123
|
-
const client = await clients.get(event.clientId);
|
|
124
|
-
if (client)
|
|
125
|
-
client.postMessage({
|
|
126
|
-
status: 'loader',
|
|
127
|
-
path,
|
|
128
|
-
});
|
|
129
|
-
else logger.warn('client not found');
|
|
130
|
-
})();
|
|
44
|
+
// Cache-First Strategy
|
|
45
|
+
event.respondWith(
|
|
46
|
+
(async () => {
|
|
47
|
+
// First, try to use the navigation preload response if it's supported.
|
|
48
|
+
try {
|
|
49
|
+
const preloadResponse = await event.preloadResponse;
|
|
50
|
+
if (preloadResponse) return preloadResponse;
|
|
51
|
+
return await fetch(event.request);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Fetch failed; returning offline page instead.', event.request.url, error);
|
|
54
|
+
// Fallback to the offline page.
|
|
55
|
+
const path = PRE_CACHED_RESOURCES.find((path) => event.request.url.match(path.replaceAll('/index.html', '')));
|
|
131
56
|
|
|
132
|
-
// We only want to call event.respondWith() if this is a navigation request
|
|
133
|
-
// for an HTML page.
|
|
134
|
-
if (path !== undefined || event.request.mode === 'navigate') {
|
|
135
|
-
event.respondWith(
|
|
136
|
-
(async () => {
|
|
137
57
|
try {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (preload) {
|
|
145
|
-
const preloadCache = await caches.has(path);
|
|
146
|
-
const cache = await caches.open(path);
|
|
147
|
-
const cacheResponse = await cache.match(path);
|
|
148
|
-
if (!preloadCache || !cacheResponse || cacheResponse.status !== 200) {
|
|
149
|
-
logger.warn('install', path);
|
|
150
|
-
// await cache.add(new Request(event.request.url, { cache: 'reload' }));
|
|
151
|
-
|
|
152
|
-
// Other option:
|
|
153
|
-
// The resource wasn't found in the cache, so fetch it from the network.
|
|
154
|
-
const fetchResponse = await fetch(event.request.url);
|
|
155
|
-
|
|
156
|
-
if (fetchResponse.status === 200) {
|
|
157
|
-
// Put the response in cache.
|
|
158
|
-
await cache.put(event.request.url, fetchResponse.clone());
|
|
159
|
-
// And return the response.
|
|
160
|
-
return fetchResponse;
|
|
161
|
-
} else {
|
|
162
|
-
await caches.delete(path);
|
|
163
|
-
throw new Error(await fetchResponse.text());
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// logger.info('cache response', path);
|
|
167
|
-
return cacheResponse;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const networkResponse = await fetch(event.request);
|
|
171
|
-
logger.warn('fetch response', event.request.url);
|
|
172
|
-
return networkResponse;
|
|
58
|
+
const cachedResponse = await caches.match(event.request);
|
|
59
|
+
if (cachedResponse) return cachedResponse;
|
|
60
|
+
const cache = await caches.open(CACHE_NAME);
|
|
61
|
+
const preCachedResponse = await cache.match(path);
|
|
62
|
+
if (!preCachedResponse) throw new Error(error.message);
|
|
63
|
+
return preCachedResponse;
|
|
173
64
|
} catch (error) {
|
|
174
|
-
|
|
175
|
-
// due to a network error.
|
|
176
|
-
// If fetch() returns a valid HTTP response with a response code in
|
|
177
|
-
// the 4xx or 5xx range, the catch() will NOT be called.
|
|
178
|
-
if (path) {
|
|
179
|
-
const preloadCache = await caches.has(path);
|
|
180
|
-
if (preloadCache) await caches.delete(path);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
logger.error('Fetch failed; returning offline page instead.', { error, path });
|
|
65
|
+
console.error('Error opening cache for pre cached page', event.request.url, error);
|
|
184
66
|
try {
|
|
185
|
-
const cache = await caches.open(
|
|
186
|
-
const
|
|
187
|
-
|
|
67
|
+
const cache = await caches.open(CACHE_NAME);
|
|
68
|
+
const preCachedResponse = await cache.match(`${PROXY_PATH === '/' ? '' : PROXY_PATH}/offline/index.html`);
|
|
69
|
+
if (!preCachedResponse) throw new Error(error.message);
|
|
70
|
+
return preCachedResponse;
|
|
188
71
|
} catch (error) {
|
|
189
|
-
|
|
190
|
-
const response = new Response(JSON.stringify({ status: 'error', message:
|
|
72
|
+
console.error('Error opening cache for offline page', event.request.url, error);
|
|
73
|
+
const response = new Response(JSON.stringify({ status: 'error', message: error.message }));
|
|
191
74
|
// response.status = 200;
|
|
192
75
|
response.headers.set('Content-Type', 'application/json');
|
|
193
76
|
return response;
|
|
194
77
|
}
|
|
195
78
|
}
|
|
196
|
-
}
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// If our if() condition is false, then this fetch handler won't intercept the
|
|
201
|
-
// request. If there are any other fetch handlers registered, they will get a
|
|
202
|
-
// chance to call event.respondWith(). If no fetch handlers call
|
|
203
|
-
// event.respondWith(), the request will be handled by the browser as if there
|
|
204
|
-
// were no service worker involvement.
|
|
79
|
+
}
|
|
80
|
+
})(),
|
|
81
|
+
);
|
|
205
82
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from 'fs-extra';
|
|
1
|
+
import { ssrFactory } from '../server/client-formatted.js';
|
|
3
2
|
|
|
4
3
|
const EmailRender = {
|
|
5
4
|
style: {
|
|
@@ -58,8 +57,7 @@ const EmailRender = {
|
|
|
58
57
|
const templates = {};
|
|
59
58
|
for (const templateKey of Object.keys(options.templates)) {
|
|
60
59
|
const ssrEmailComponent = options.templates[templateKey];
|
|
61
|
-
|
|
62
|
-
eval(await srcFormatted(fs.readFileSync(`./src/client/ssr/components/email/${ssrEmailComponent}.js`, 'utf8')));
|
|
60
|
+
const SrrComponent = await ssrFactory(`./src/client/ssr/mailer/${ssrEmailComponent}.js`);
|
|
63
61
|
templates[templateKey] = SrrComponent(this, options);
|
|
64
62
|
}
|
|
65
63
|
return templates;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
|
-
import { srcFormatted, componentFormatted, viewFormatted, ssrFactory } from './client-formatted.js';
|
|
4
|
+
import { srcFormatted, componentFormatted, viewFormatted, ssrFactory, JSONweb } from './client-formatted.js';
|
|
5
5
|
import { loggerFactory } from './logger.js';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
cap,
|
|
8
|
+
getCapVariableName,
|
|
9
|
+
newInstance,
|
|
10
|
+
orderArrayFromAttrInt,
|
|
11
|
+
titleFormatted,
|
|
12
|
+
uniqueArray,
|
|
13
|
+
} from '../client/components/core/CommonJs.js';
|
|
7
14
|
import UglifyJS from 'uglify-js';
|
|
8
15
|
import { minify } from 'html-minifier-terser';
|
|
9
16
|
import dotenv from 'dotenv';
|
|
@@ -131,16 +138,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
131
138
|
const enableLiveRebuild =
|
|
132
139
|
options && options.liveClientBuildPaths && options.liveClientBuildPaths.length > 0 ? true : false;
|
|
133
140
|
|
|
134
|
-
// common ssr components
|
|
135
|
-
let jsSsrCommonComponents = '';
|
|
136
|
-
{
|
|
137
|
-
const files = await fs.readdir(`./src/client/ssr/common`);
|
|
138
|
-
for (const relativePath of files)
|
|
139
|
-
jsSsrCommonComponents += await srcFormatted(
|
|
140
|
-
fs.readFileSync(`./src/client/ssr/common/${relativePath}`, 'utf8').split('export')[0],
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
141
|
let currentPort = parseInt(process.env.PORT) + 1;
|
|
145
142
|
for (const host of Object.keys(confServer)) {
|
|
146
143
|
const paths = orderArrayFromAttrInt(Object.keys(confServer[host]), 'length', 'asc');
|
|
@@ -167,6 +164,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
167
164
|
apiBaseHost,
|
|
168
165
|
ttiLoadTimeLimit,
|
|
169
166
|
singleReplica,
|
|
167
|
+
offlineBuild,
|
|
170
168
|
} = confServer[host][path];
|
|
171
169
|
if (singleReplica) continue;
|
|
172
170
|
if (!confClient[client]) confClient[client] = {};
|
|
@@ -308,57 +306,22 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
308
306
|
|
|
309
307
|
const buildId = `${client}.index`;
|
|
310
308
|
const siteMapLinks = [];
|
|
311
|
-
|
|
312
|
-
|
|
309
|
+
const ssrPath = path === '/' ? path : `${path}/`;
|
|
310
|
+
const Render = await ssrFactory();
|
|
313
311
|
|
|
314
312
|
if (views) {
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (jsSrc.split('/*imports*/')[1]) jsSrc = jsSrc.split('/*imports*/')[1];
|
|
319
|
-
if (filter) jsSrc = await filter(jsSrc);
|
|
320
|
-
fs.writeFileSync(
|
|
321
|
-
jsPublicPath,
|
|
322
|
-
minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
|
|
323
|
-
'utf8',
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
// service woker
|
|
329
|
-
await buildJsSrcPage(
|
|
330
|
-
fs.existsSync(`./src/client/sw/${publicClientId}.sw.js`)
|
|
331
|
-
? `./src/client/sw/${publicClientId}.sw.js`
|
|
332
|
-
: `./src/client/sw/default.sw.js`,
|
|
333
|
-
`${rootClientPath}/sw.js`,
|
|
334
|
-
path !== '/'
|
|
335
|
-
? (jsSrc) => jsSrc.replaceAll(`const PROXY_PATH = '/';`, `const PROXY_PATH = '${path}/';`)
|
|
336
|
-
: undefined,
|
|
337
|
-
);
|
|
313
|
+
const jsSrcPath = fs.existsSync(`./src/client/sw/${publicClientId}.sw.js`)
|
|
314
|
+
? `./src/client/sw/${publicClientId}.sw.js`
|
|
315
|
+
: `./src/client/sw/default.sw.js`;
|
|
338
316
|
|
|
339
|
-
|
|
340
|
-
for (const page of await fs.readdir('./src/client/ssr/pages')) {
|
|
341
|
-
await buildJsSrcPage(`./src/client/ssr/pages/${page}`, `${rootClientPath}/${page}`);
|
|
317
|
+
const jsPublicPath = `${rootClientPath}/sw.js`;
|
|
342
318
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
ssrPath: '/',
|
|
346
|
-
ssrHeadComponents: '',
|
|
347
|
-
ssrBodyComponents: '',
|
|
348
|
-
baseSsrLib: jsSsrCommonComponents + fs.readFileSync(`${rootClientPath}/${page}`, 'utf8'),
|
|
349
|
-
});
|
|
319
|
+
if (!(enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath))) {
|
|
320
|
+
const jsSrc = viewFormatted(await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')), dists, path, baseHost);
|
|
350
321
|
|
|
351
322
|
fs.writeFileSync(
|
|
352
|
-
|
|
353
|
-
minifyBuild || process.env.NODE_ENV === 'production'
|
|
354
|
-
? await minify(htmlSrc, {
|
|
355
|
-
minifyCSS: true,
|
|
356
|
-
minifyJS: true,
|
|
357
|
-
collapseBooleanAttributes: true,
|
|
358
|
-
collapseInlineTagWhitespace: true,
|
|
359
|
-
collapseWhitespace: true,
|
|
360
|
-
})
|
|
361
|
-
: htmlSrc,
|
|
323
|
+
jsPublicPath,
|
|
324
|
+
minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
|
|
362
325
|
'utf8',
|
|
363
326
|
);
|
|
364
327
|
}
|
|
@@ -404,7 +367,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
404
367
|
const canonicalURL = `https://${host}${path}${
|
|
405
368
|
view.path === '/' ? (path === '/' ? '' : '/') : path === '/' ? `${view.path.slice(1)}/` : `${view.path}/`
|
|
406
369
|
}`;
|
|
407
|
-
const ssrPath = path === '/' ? path : `${path}/`;
|
|
408
370
|
|
|
409
371
|
let ssrHeadComponents = ``;
|
|
410
372
|
let ssrBodyComponents = ``;
|
|
@@ -414,10 +376,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
414
376
|
confSSR[view.ssr].head.unshift('Production');
|
|
415
377
|
|
|
416
378
|
for (const ssrHeadComponent of confSSR[view.ssr].head) {
|
|
417
|
-
const SrrComponent = await ssrFactory(
|
|
418
|
-
`./src/client/ssr/components/head/${ssrHeadComponent}.js`,
|
|
419
|
-
jsSsrCommonComponents,
|
|
420
|
-
);
|
|
379
|
+
const SrrComponent = await ssrFactory(`./src/client/ssr/head/${ssrHeadComponent}.js`);
|
|
421
380
|
|
|
422
381
|
switch (ssrHeadComponent) {
|
|
423
382
|
case 'Pwa':
|
|
@@ -498,10 +457,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
498
457
|
}
|
|
499
458
|
|
|
500
459
|
for (const ssrBodyComponent of confSSR[view.ssr].body) {
|
|
501
|
-
const SrrComponent = await ssrFactory(
|
|
502
|
-
`./src/client/ssr/components/body/${ssrBodyComponent}.js`,
|
|
503
|
-
jsSsrCommonComponents,
|
|
504
|
-
);
|
|
460
|
+
const SrrComponent = await ssrFactory(`./src/client/ssr/body/${ssrBodyComponent}.js`);
|
|
505
461
|
switch (ssrBodyComponent) {
|
|
506
462
|
case 'UnderpostDefaultSplashScreen':
|
|
507
463
|
case 'CyberiaDefaultSplashScreen':
|
|
@@ -544,14 +500,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
544
500
|
}
|
|
545
501
|
}
|
|
546
502
|
}
|
|
547
|
-
const htmlSrc = Render({
|
|
548
|
-
title,
|
|
549
|
-
buildId,
|
|
550
|
-
ssrPath,
|
|
551
|
-
ssrHeadComponents,
|
|
552
|
-
ssrBodyComponents,
|
|
553
|
-
baseSsrLib: jsSsrCommonComponents,
|
|
554
|
-
});
|
|
555
503
|
|
|
556
504
|
/** @type {import('sitemap').SitemapItem} */
|
|
557
505
|
const siteMapLink = {
|
|
@@ -561,6 +509,14 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
|
|
|
561
509
|
};
|
|
562
510
|
siteMapLinks.push(siteMapLink);
|
|
563
511
|
|
|
512
|
+
const htmlSrc = Render({
|
|
513
|
+
title,
|
|
514
|
+
buildId,
|
|
515
|
+
ssrPath,
|
|
516
|
+
ssrHeadComponents,
|
|
517
|
+
ssrBodyComponents,
|
|
518
|
+
});
|
|
519
|
+
|
|
564
520
|
fs.writeFileSync(
|
|
565
521
|
`${buildPath}index.html`,
|
|
566
522
|
minifyBuild || process.env.NODE_ENV === 'production'
|
|
@@ -766,6 +722,76 @@ root file where the route starts, such as index.js, app.js, routes.js, etc ... *
|
|
|
766
722
|
|
|
767
723
|
zip.writeZip(`./build/${buildId}.zip`);
|
|
768
724
|
}
|
|
725
|
+
if (client) {
|
|
726
|
+
let PRE_CACHED_RESOURCES = [];
|
|
727
|
+
|
|
728
|
+
if (views && offlineBuild && fs.existsSync(`${rootClientPath}/sw.js`)) {
|
|
729
|
+
PRE_CACHED_RESOURCES = await fs.readdir(rootClientPath, { recursive: true });
|
|
730
|
+
PRE_CACHED_RESOURCES = views
|
|
731
|
+
.map((view) => `${path === '/' ? '' : path}${view.path}`)
|
|
732
|
+
.concat(
|
|
733
|
+
PRE_CACHED_RESOURCES.map((p) => `/${p}`).filter(
|
|
734
|
+
(p) => p[1] !== '.' && !fs.statSync(`${rootClientPath}${p}`).isDirectory(),
|
|
735
|
+
),
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
for (const pageType of ['offline', 'pages']) {
|
|
740
|
+
if (confSSR[getCapVariableName(client)] && confSSR[getCapVariableName(client)][pageType]) {
|
|
741
|
+
for (const page of confSSR[getCapVariableName(client)][pageType]) {
|
|
742
|
+
const SsrComponent = await ssrFactory(`./src/client/ssr/${pageType}/${page.client}.js`);
|
|
743
|
+
|
|
744
|
+
const htmlSrc = Render({
|
|
745
|
+
title: page.title,
|
|
746
|
+
ssrPath,
|
|
747
|
+
ssrHeadComponents: '',
|
|
748
|
+
ssrBodyComponents: SsrComponent(),
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
const buildPath = `${
|
|
752
|
+
rootClientPath[rootClientPath.length - 1] === '/' ? rootClientPath.slice(0, -1) : rootClientPath
|
|
753
|
+
}${page.path === '/' ? page.path : `${page.path}/`}`;
|
|
754
|
+
|
|
755
|
+
PRE_CACHED_RESOURCES.push(`${path === '/' ? '' : path}${page.path === '/' ? '' : page.path}/index.html`);
|
|
756
|
+
|
|
757
|
+
if (!fs.existsSync(buildPath)) fs.mkdirSync(buildPath, { recursive: true });
|
|
758
|
+
|
|
759
|
+
const buildHtmlPath = `${buildPath}index.html`;
|
|
760
|
+
|
|
761
|
+
logger.info('ssr page build', buildHtmlPath);
|
|
762
|
+
|
|
763
|
+
fs.writeFileSync(
|
|
764
|
+
buildHtmlPath,
|
|
765
|
+
minifyBuild || process.env.NODE_ENV === 'production'
|
|
766
|
+
? await minify(htmlSrc, {
|
|
767
|
+
minifyCSS: true,
|
|
768
|
+
minifyJS: true,
|
|
769
|
+
collapseBooleanAttributes: true,
|
|
770
|
+
collapseInlineTagWhitespace: true,
|
|
771
|
+
collapseWhitespace: true,
|
|
772
|
+
})
|
|
773
|
+
: htmlSrc,
|
|
774
|
+
'utf8',
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
{
|
|
781
|
+
const PRE_CACHED_JSON = `PRE_CACHED_RESOURCES = ${JSONweb(uniqueArray(PRE_CACHED_RESOURCES))}`;
|
|
782
|
+
const PROXY_PATH = `PROXY_PATH = '${path}'`;
|
|
783
|
+
fs.writeFileSync(
|
|
784
|
+
`${rootClientPath}/sw.js`,
|
|
785
|
+
fs
|
|
786
|
+
.readFileSync(`${rootClientPath}/sw.js`, 'utf8')
|
|
787
|
+
.replaceAll(`PRE_CACHED_RESOURCES = []`, PRE_CACHED_JSON)
|
|
788
|
+
.replaceAll(`PRE_CACHED_RESOURCES=[]`, PRE_CACHED_JSON)
|
|
789
|
+
.replaceAll(`PROXY_PATH = '/'`, PROXY_PATH)
|
|
790
|
+
.replaceAll(`PROXY_PATH='/'`, PROXY_PATH),
|
|
791
|
+
'utf8',
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
769
795
|
}
|
|
770
796
|
}
|
|
771
797
|
};
|
|
@@ -47,11 +47,9 @@ const viewFormatted = (src, dists, proxyPath, baseHost = '') => {
|
|
|
47
47
|
return src.replaceAll(`from './`, componentFromFormatted).replaceAll(`from '../`, componentFromFormatted);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const ssrFactory = async (componentPath =
|
|
50
|
+
const ssrFactory = async (componentPath = `./src/client/ssr/Render.js`) => {
|
|
51
51
|
let SrrComponent = () => {};
|
|
52
|
-
|
|
53
|
-
if (render.split('/*imports*/')[1]) render = render.split('/*imports*/')[1];
|
|
54
|
-
eval(jsSsrCommonComponents + render);
|
|
52
|
+
eval(await srcFormatted(fs.readFileSync(componentPath, 'utf8')));
|
|
55
53
|
return SrrComponent;
|
|
56
54
|
};
|
|
57
55
|
|
package/src/server/conf.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import dotenv from 'dotenv';
|
|
3
|
-
import {
|
|
3
|
+
import { capFirst, getCapVariableName, newInstance, range, timer } from '../client/components/core/CommonJs.js';
|
|
4
4
|
import * as dir from 'path';
|
|
5
5
|
import cliProgress from 'cli-progress';
|
|
6
6
|
import cliSpinners from 'cli-spinners';
|
|
7
7
|
import logUpdate from 'log-update';
|
|
8
8
|
import colors from 'colors';
|
|
9
9
|
import { loggerFactory } from './logger.js';
|
|
10
|
-
import { shellExec
|
|
10
|
+
import { shellExec } from './process.js';
|
|
11
11
|
import { DefaultConf } from '../../conf.js';
|
|
12
12
|
import ncp from 'copy-paste';
|
|
13
13
|
import read from 'read';
|
|
14
14
|
import splitFile from 'split-file';
|
|
15
15
|
import axios from 'axios';
|
|
16
16
|
import https from 'https';
|
|
17
|
+
import { ssrFactory } from './client-formatted.js';
|
|
17
18
|
|
|
18
19
|
// axios.defaults.baseURL = BASE_URL;
|
|
19
20
|
|
|
@@ -466,6 +467,16 @@ const buildProxyRouter = () => {
|
|
|
466
467
|
}
|
|
467
468
|
}
|
|
468
469
|
}
|
|
470
|
+
if (process.argv.includes('maintenance'))
|
|
471
|
+
(async () => {
|
|
472
|
+
globalThis.defaultHtmlSrcMaintenance = (await ssrFactory())({
|
|
473
|
+
title: 'Site in maintenance',
|
|
474
|
+
ssrPath: '/',
|
|
475
|
+
ssrHeadComponents: '',
|
|
476
|
+
ssrBodyComponents: (await ssrFactory(`./src/client/ssr/body/Maintenance.js`))(),
|
|
477
|
+
});
|
|
478
|
+
})();
|
|
479
|
+
|
|
469
480
|
return proxyRouter;
|
|
470
481
|
};
|
|
471
482
|
|
|
@@ -596,14 +607,32 @@ const validateTemplatePath = (absolutePath = '') => {
|
|
|
596
607
|
return false;
|
|
597
608
|
}
|
|
598
609
|
if (
|
|
599
|
-
absolutePath.match('src/client/ssr/
|
|
600
|
-
!confSsr.body.find((p) => absolutePath.match(`src/client/ssr/
|
|
610
|
+
absolutePath.match('src/client/ssr/body') &&
|
|
611
|
+
!confSsr.body.find((p) => absolutePath.match(`src/client/ssr/body/${p}.js`))
|
|
612
|
+
) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
if (
|
|
616
|
+
absolutePath.match('src/client/ssr/head') &&
|
|
617
|
+
!confSsr.head.find((p) => absolutePath.match(`src/client/ssr/head/${p}.js`))
|
|
618
|
+
) {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
if (
|
|
622
|
+
absolutePath.match('src/client/ssr/mailer') &&
|
|
623
|
+
!Object.keys(confSsr.mailer).find((p) => absolutePath.match(`src/client/ssr/mailer/${confSsr.mailer[p]}.js`))
|
|
624
|
+
) {
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
if (
|
|
628
|
+
absolutePath.match('src/client/ssr/offline') &&
|
|
629
|
+
!confSsr.offline.find((p) => absolutePath.match(`src/client/ssr/offline/${p.client}.js`))
|
|
601
630
|
) {
|
|
602
631
|
return false;
|
|
603
632
|
}
|
|
604
633
|
if (
|
|
605
|
-
absolutePath.match('src/client/ssr/
|
|
606
|
-
!confSsr.
|
|
634
|
+
absolutePath.match('src/client/ssr/pages') &&
|
|
635
|
+
!confSsr.pages.find((p) => absolutePath.match(`src/client/ssr/pages/${p.client}.js`))
|
|
607
636
|
) {
|
|
608
637
|
return false;
|
|
609
638
|
}
|
|
@@ -891,13 +920,12 @@ const fixDependencies = async () => {
|
|
|
891
920
|
);
|
|
892
921
|
};
|
|
893
922
|
|
|
894
|
-
const maintenancePath = `${getRootDirectory()}/public/${process.env.DEFAULT_DEPLOY_HOST}${
|
|
895
|
-
process.env.DEFAULT_DEPLOY_PATH
|
|
896
|
-
}/maintenance.html`;
|
|
897
|
-
|
|
898
923
|
const maintenanceMiddleware = (req, res, port, proxyRouter) => {
|
|
899
|
-
if (process.argv.includes('maintenance') &&
|
|
900
|
-
if (req.method.toUpperCase() === 'GET')
|
|
924
|
+
if (process.argv.includes('maintenance') && globalThis.defaultHtmlSrcMaintenance) {
|
|
925
|
+
if (req.method.toUpperCase() === 'GET') {
|
|
926
|
+
res.set('Content-Type', 'text/html');
|
|
927
|
+
return res.status(503).send(globalThis.defaultHtmlSrcMaintenance);
|
|
928
|
+
}
|
|
901
929
|
return res.status(503).json({
|
|
902
930
|
status: 'error',
|
|
903
931
|
message: 'Server is under maintenance',
|
|
@@ -941,7 +969,6 @@ export {
|
|
|
941
969
|
mergeBackUp,
|
|
942
970
|
fixDependencies,
|
|
943
971
|
getDeployId,
|
|
944
|
-
maintenancePath,
|
|
945
972
|
maintenanceMiddleware,
|
|
946
973
|
setUpProxyMaintenanceServer,
|
|
947
974
|
};
|
package/src/server/proxy.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import express from 'express';
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
4
|
import dotenv from 'dotenv';
|
|
6
5
|
|
|
7
6
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
@@ -10,7 +9,6 @@ import { listenPortController, network } from './network.js';
|
|
|
10
9
|
import { orderArrayFromAttrInt } from '../client/components/core/CommonJs.js';
|
|
11
10
|
import { createSslServer, sslRedirectMiddleware } from './ssl.js';
|
|
12
11
|
import { buildProxyRouter, maintenanceMiddleware } from './conf.js';
|
|
13
|
-
import { getRootDirectory } from './process.js';
|
|
14
12
|
|
|
15
13
|
dotenv.config();
|
|
16
14
|
|