underpost 2.7.91 → 2.7.93
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 +29 -5
- package/docker-compose.yml +1 -1
- package/package.json +133 -133
- package/src/client/Default.index.js +2 -1
- 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 +8 -6
- package/src/client/components/core/Scroll.js +65 -1
- package/src/client/components/core/Translate.js +21 -5
- package/src/client/components/core/VanillaJs.js +4 -1
- package/src/client/components/core/Worker.js +10 -11
- package/src/client/components/default/MenuDefault.js +69 -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/body/404.js +73 -0
- package/src/client/ssr/body/500.js +72 -0
- 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 +67 -0
- package/src/client/ssr/pages/Test.js +198 -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,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
|
|
package/src/server/runtime.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createServer } from 'http';
|
|
|
11
11
|
import { getRootDirectory } from './process.js';
|
|
12
12
|
import { network, listenPortController, saveRuntimeRouter, logRuntimeRouter, listenServerFactory } from './network.js';
|
|
13
13
|
import { loggerFactory, loggerMiddleware } from './logger.js';
|
|
14
|
-
import { newInstance } from '../client/components/core/CommonJs.js';
|
|
14
|
+
import { getCapVariableName, newInstance } from '../client/components/core/CommonJs.js';
|
|
15
15
|
import { Xampp } from '../runtime/xampp/Xampp.js';
|
|
16
16
|
import { MailerProvider } from '../mailer/MailerProvider.js';
|
|
17
17
|
import { DataBaseProvider } from '../db/DataBaseProvider.js';
|
|
@@ -19,6 +19,7 @@ import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
|
19
19
|
import { createPeerServer } from './peer.js';
|
|
20
20
|
import { Lampp } from '../runtime/lampp/Lampp.js';
|
|
21
21
|
import { getDeployId } from './conf.js';
|
|
22
|
+
import { ssrFactory } from './client-formatted.js';
|
|
22
23
|
|
|
23
24
|
dotenv.config();
|
|
24
25
|
|
|
@@ -58,6 +59,7 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
58
59
|
const initPort = parseInt(process.env.PORT) + 1;
|
|
59
60
|
let currentPort = initPort;
|
|
60
61
|
const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
|
|
62
|
+
const confSSR = JSON.parse(fs.readFileSync(`./conf/conf.ssr.json`, 'utf8'));
|
|
61
63
|
const singleReplicaHosts = [];
|
|
62
64
|
for (const host of Object.keys(confServer)) {
|
|
63
65
|
if (singleReplicaHosts.length > 0 && !singleReplicaHosts.includes(host)) {
|
|
@@ -310,7 +312,7 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
310
312
|
app.use(fileUpload());
|
|
311
313
|
|
|
312
314
|
// json formatted response
|
|
313
|
-
app.set('json spaces', 2);
|
|
315
|
+
if (process.env.NODE_ENV === 'development') app.set('json spaces', 2);
|
|
314
316
|
|
|
315
317
|
// lang handling middleware
|
|
316
318
|
app.use(function (req, res, next) {
|
|
@@ -365,15 +367,17 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
365
367
|
|
|
366
368
|
if (db && apis) await DataBaseProvider.load({ apis, host, path, db });
|
|
367
369
|
|
|
368
|
-
if (mailer)
|
|
370
|
+
if (mailer) {
|
|
371
|
+
const mailerSsrConf = confSSR[getCapVariableName(client)];
|
|
369
372
|
await MailerProvider.load({
|
|
370
373
|
id: `${host}${path}`,
|
|
371
374
|
meta: `mailer-${host}${path}`,
|
|
372
375
|
host,
|
|
373
376
|
path,
|
|
374
377
|
...mailer,
|
|
378
|
+
templates: mailerSsrConf ? mailerSsrConf.mailer : {},
|
|
375
379
|
});
|
|
376
|
-
|
|
380
|
+
}
|
|
377
381
|
if (apis) {
|
|
378
382
|
const apiPath = `${path === '/' ? '' : path}/${process.env.BASE_API}`;
|
|
379
383
|
for (const api of apis)
|
|
@@ -385,17 +389,41 @@ export PATH=$PATH:/opt/lampp/bin`,
|
|
|
385
389
|
app.use(`${apiPath}/${api}`, router);
|
|
386
390
|
})();
|
|
387
391
|
}
|
|
392
|
+
|
|
393
|
+
const Render = await ssrFactory();
|
|
394
|
+
const ssrPath = path === '/' ? path : `${path}/`;
|
|
395
|
+
|
|
396
|
+
const defaultHtmlSrc404 = Render({
|
|
397
|
+
title: '404 Not Found',
|
|
398
|
+
ssrPath,
|
|
399
|
+
ssrHeadComponents: '',
|
|
400
|
+
ssrBodyComponents: (await ssrFactory(`./src/client/ssr/body/404.js`))(),
|
|
401
|
+
});
|
|
402
|
+
const path404 = `${directory ? directory : `${getRootDirectory()}${rootHostPath}`}/404/index.html`;
|
|
403
|
+
const page404 = fs.existsSync(path404) ? `${path === '/' ? '' : path}/404` : undefined;
|
|
388
404
|
app.use(function (req, res, next) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
405
|
+
if (page404) return res.status(404).redirect(page404);
|
|
406
|
+
else {
|
|
407
|
+
res.set('Content-Type', 'text/html');
|
|
408
|
+
return res.status(404).send(defaultHtmlSrc404);
|
|
409
|
+
}
|
|
392
410
|
});
|
|
393
411
|
|
|
412
|
+
const defaultHtmlSrc500 = Render({
|
|
413
|
+
title: '500 Server Error',
|
|
414
|
+
ssrPath,
|
|
415
|
+
ssrHeadComponents: '',
|
|
416
|
+
ssrBodyComponents: (await ssrFactory(`./src/client/ssr/body/500.js`))(),
|
|
417
|
+
});
|
|
418
|
+
const path500 = `${directory ? directory : `${getRootDirectory()}${rootHostPath}`}/500/index.html`;
|
|
419
|
+
const page500 = fs.existsSync(path500) ? `${path === '/' ? '' : path}/500` : undefined;
|
|
394
420
|
app.use(function (err, req, res, next) {
|
|
395
421
|
logger.error(err, err.stack);
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
422
|
+
if (page500) return res.status(500).redirect(page500);
|
|
423
|
+
else {
|
|
424
|
+
res.set('Content-Type', 'text/html');
|
|
425
|
+
return res.status(500).send(defaultHtmlSrc500);
|
|
426
|
+
}
|
|
399
427
|
});
|
|
400
428
|
|
|
401
429
|
// instance server
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
const s = (el) => document.querySelector(el);
|
|
2
|
-
|
|
3
|
-
const append = (el, html) => s(el).insertAdjacentHTML('beforeend', html);
|
|
4
|
-
|
|
5
|
-
const htmls = (el, html) => (s(el).innerHTML = html);
|
|
6
|
-
|
|
7
|
-
const s4 = () => (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
8
|
-
|
|
9
|
-
const range = (start, end) => {
|
|
10
|
-
return end < start
|
|
11
|
-
? range(end, start).reverse()
|
|
12
|
-
: Array.apply(0, Array(end - start + 1)).map((element, index) => index + start);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
|
|
16
|
-
|
|
17
|
-
const newInstance = (obj) => {
|
|
18
|
-
// structuredClone() 2022 ES6 feature
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(JSON.stringify(obj));
|
|
21
|
-
} catch (error) {
|
|
22
|
-
return { error: error.message };
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const fullScreenIn = () => {
|
|
27
|
-
const elem = document.documentElement;
|
|
28
|
-
if (elem.requestFullscreen) {
|
|
29
|
-
elem.requestFullscreen();
|
|
30
|
-
} else if (elem.mozRequestFullScreen) {
|
|
31
|
-
/* Firefox */
|
|
32
|
-
elem.mozRequestFullScreen();
|
|
33
|
-
} else if (elem.webkitRequestFullscreen) {
|
|
34
|
-
/* Chrome, Safari & Opera */
|
|
35
|
-
elem.webkitRequestFullscreen();
|
|
36
|
-
} else if (elem.msRequestFullscreen) {
|
|
37
|
-
/* IE/Edge */
|
|
38
|
-
elem = window.top.document.body; //To break out of frame in IE
|
|
39
|
-
elem.msRequestFullscreen();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const borderChar = (px, color, selectors) => {
|
|
44
|
-
if (selectors) {
|
|
45
|
-
return selectors
|
|
46
|
-
.map(
|
|
47
|
-
(selector) => html`
|
|
48
|
-
<style>
|
|
49
|
-
${selector} {
|
|
50
|
-
text-shadow: ${px}px -${px}px ${px}px ${color}, -${px}px ${px}px ${px}px ${color},
|
|
51
|
-
-${px}px -${px}px ${px}px ${color}, ${px}px ${px}px ${px}px ${color};
|
|
52
|
-
}
|
|
53
|
-
</style>
|
|
54
|
-
`,
|
|
55
|
-
)
|
|
56
|
-
.join('');
|
|
57
|
-
}
|
|
58
|
-
return html`
|
|
59
|
-
text-shadow: ${px}px -${px}px ${px}px ${color}, -${px}px ${px}px ${px}px ${color}, -${px}px -${px}px ${px}px
|
|
60
|
-
${color}, ${px}px ${px}px ${px}px ${color};
|
|
61
|
-
`;
|
|
62
|
-
};
|
|
63
|
-
const getLang = () =>
|
|
64
|
-
localStorage.getItem('lang') ? localStorage.getItem('lang') : navigator.language || navigator.userLanguage;
|
|
65
|
-
|
|
66
|
-
const loggerFactory = (meta) => {
|
|
67
|
-
meta = meta.url.split('/').pop();
|
|
68
|
-
const types = ['error', 'warn', 'info', 'debug'];
|
|
69
|
-
const logger = {
|
|
70
|
-
log: function (type, args) {
|
|
71
|
-
if (location.hostname !== 'localhost' && console.log() !== null) {
|
|
72
|
-
console.log = () => null;
|
|
73
|
-
console.error = () => null;
|
|
74
|
-
console.info = () => null;
|
|
75
|
-
console.warn = () => null;
|
|
76
|
-
}
|
|
77
|
-
return location.hostname === 'localhost'
|
|
78
|
-
? console[type](`[${meta}] ${new Date().toISOString()} ${type}:`, ...args)
|
|
79
|
-
: null;
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
types.map(
|
|
83
|
-
(type) =>
|
|
84
|
-
(logger[type] = function (...args) {
|
|
85
|
-
return this.log(type, args);
|
|
86
|
-
}),
|
|
87
|
-
);
|
|
88
|
-
return logger;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export { getLang, s, append, s4, range, timer, htmls, newInstance, fullScreenIn, borderChar, loggerFactory };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const TranslateCore = {
|
|
2
|
-
['server-maintenance']: {
|
|
3
|
-
en: "The server is under maintenance <br> we'll be back soon.",
|
|
4
|
-
es: 'El servidor está en mantenimiento <br> volveremos pronto.',
|
|
5
|
-
},
|
|
6
|
-
['no-internet-connection']: {
|
|
7
|
-
en: 'No internet connection <br> verify your network',
|
|
8
|
-
es: 'Sin conexión a internet <br> verifica tu red',
|
|
9
|
-
},
|
|
10
|
-
['page-not-found']: {
|
|
11
|
-
en: 'Page not found',
|
|
12
|
-
es: 'Página no encontrada',
|
|
13
|
-
},
|
|
14
|
-
['page-broken']: {
|
|
15
|
-
es: 'Algo salio mal',
|
|
16
|
-
en: 'Something went wrong',
|
|
17
|
-
},
|
|
18
|
-
['back']: {
|
|
19
|
-
en: 'Back to <br> homepage',
|
|
20
|
-
es: 'Volver a <br> la pagina principal',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const Translate = (key) => TranslateCore[key][getLang().match('es') ? 'es' : 'en'];
|
|
25
|
-
|
|
26
|
-
export { Translate };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const Worker = {
|
|
2
|
-
instance: async function (options = { render: async () => {} }) {
|
|
3
|
-
window.serviceWorkerReady = true;
|
|
4
|
-
append(
|
|
5
|
-
'body',
|
|
6
|
-
html`
|
|
7
|
-
<style>
|
|
8
|
-
body {
|
|
9
|
-
background-color: #dcdcdc;
|
|
10
|
-
color: #303030;
|
|
11
|
-
font-family: arial;
|
|
12
|
-
font-size: 16px;
|
|
13
|
-
}
|
|
14
|
-
.page-render {
|
|
15
|
-
min-height: 100vh;
|
|
16
|
-
}
|
|
17
|
-
a {
|
|
18
|
-
color: #000000;
|
|
19
|
-
}
|
|
20
|
-
</style>
|
|
21
|
-
<div class="in page-render"></div>
|
|
22
|
-
`,
|
|
23
|
-
);
|
|
24
|
-
await options.render();
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { Worker };
|