@silexlabs/silex 3.0.0-alpha.39 → 3.0.0-alpha.41

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 (110) hide show
  1. package/.silex.js +38 -8
  2. package/dist/client/client/config.d.ts +11 -41
  3. package/dist/client/client/grapesjs/LoginDialog.d.ts +13 -0
  4. package/dist/client/client/grapesjs/PublicationManager.d.ts +69 -0
  5. package/dist/client/client/grapesjs/PublicationUi.d.ts +58 -0
  6. package/dist/client/client/grapesjs/index.d.ts +18 -44
  7. package/dist/client/client/grapesjs/storage.d.ts +1 -0
  8. package/dist/client/client/services.d.ts +35 -0
  9. package/dist/client/constants.d.ts +17 -0
  10. package/dist/client/css/admin.css +86 -3
  11. package/dist/client/js/main.js +201 -90
  12. package/dist/client/js/main.js.LICENSE.txt +6 -0
  13. package/dist/client/types.d.ts +200 -29
  14. package/dist/constants.d.ts +21 -0
  15. package/dist/constants.js +38 -1
  16. package/dist/constants.js.map +1 -0
  17. package/dist/events.d.ts +2 -0
  18. package/dist/events.js +17 -0
  19. package/dist/events.js.map +1 -0
  20. package/dist/plugins/AuthPlugin.d.ts +1 -0
  21. package/dist/plugins/AuthPlugin.js +38 -0
  22. package/dist/plugins/AuthPlugin.js.map +1 -0
  23. package/dist/plugins/Cache.d.ts +2 -0
  24. package/dist/plugins/Cache.js +32 -0
  25. package/dist/plugins/Cache.js.map +1 -0
  26. package/dist/plugins/FtpBackend.d.ts +92 -0
  27. package/dist/plugins/FtpBackend.js +604 -0
  28. package/dist/plugins/FtpBackend.js.map +1 -0
  29. package/dist/plugins/HooksPlugin.d.ts +7 -0
  30. package/dist/plugins/HooksPlugin.js +76 -0
  31. package/dist/plugins/HooksPlugin.js.map +1 -0
  32. package/dist/plugins/PublicationPlugin.d.ts +17 -0
  33. package/dist/plugins/PublicationPlugin.js +170 -0
  34. package/dist/plugins/PublicationPlugin.js.map +1 -0
  35. package/dist/plugins/SslPlugin.d.ts +1 -0
  36. package/dist/plugins/SslPlugin.js +86 -0
  37. package/dist/plugins/SslPlugin.js.map +1 -0
  38. package/dist/plugins/StaticPlugin.d.ts +1 -0
  39. package/dist/plugins/StaticPlugin.js +66 -0
  40. package/dist/plugins/StaticPlugin.js.map +1 -0
  41. package/dist/plugins/WebsitePlugin.d.ts +14 -0
  42. package/dist/plugins/WebsitePlugin.js +302 -0
  43. package/dist/plugins/WebsitePlugin.js.map +1 -0
  44. package/dist/server/backends/FsBackend.d.ts +42 -0
  45. package/dist/server/backends/FsBackend.js +269 -0
  46. package/dist/server/backends/FsBackend.js.map +1 -0
  47. package/dist/server/backends/index.d.ts +95 -0
  48. package/dist/server/backends/index.js +255 -0
  49. package/dist/server/backends/index.js.map +1 -0
  50. package/dist/server/cli.js +0 -1
  51. package/dist/server/config.d.ts +58 -0
  52. package/dist/server/config.js +128 -24
  53. package/dist/server/config.js.map +1 -0
  54. package/dist/server/express.js +31 -3
  55. package/dist/server/index.js +9 -20
  56. package/dist/server/jobs.d.ts +6 -0
  57. package/dist/server/jobs.js +75 -0
  58. package/dist/server/jobs.js.map +1 -0
  59. package/dist/server/utils/validation.d.ts +7 -0
  60. package/dist/server/utils/validation.js +37 -0
  61. package/dist/server/utils/validation.js.map +1 -0
  62. package/dist/types.d.ts +270 -0
  63. package/dist/types.js +35 -28
  64. package/dist/types.js.map +1 -0
  65. package/package.json +19 -8
  66. package/public/silex.js +17 -0
  67. package/src/css/dialog.scss +9 -2
  68. package/src/css/grapesjs.scss +79 -0
  69. package/src/css/project-bar.scss +2 -2
  70. package/src/example-client-config.js +17 -0
  71. package/src/html/templates/includes.pug +0 -1
  72. package/src/ts/client/config.ts +7 -6
  73. package/src/ts/client/grapesjs/LoginDialog.ts +190 -0
  74. package/src/ts/client/grapesjs/PublicationManager.ts +333 -0
  75. package/src/ts/client/grapesjs/PublicationUi.ts +320 -0
  76. package/src/ts/client/grapesjs/index.ts +88 -85
  77. package/src/ts/client/grapesjs/storage.ts +110 -0
  78. package/src/ts/client/index.ts +5 -7
  79. package/src/ts/client/services.ts +129 -0
  80. package/src/ts/constants.ts +21 -0
  81. package/src/ts/plugins/AuthPlugin.ts +38 -0
  82. package/src/ts/plugins/Cache.ts +28 -0
  83. package/src/ts/plugins/FtpBackend.ts +689 -0
  84. package/src/ts/plugins/HooksPlugin.ts +79 -0
  85. package/src/ts/plugins/PublicationPlugin.ts +170 -0
  86. package/src/{plugins/SslPlugin.js → ts/plugins/SslPlugin.ts} +24 -6
  87. package/src/ts/plugins/StaticPlugin.ts +68 -0
  88. package/src/ts/plugins/WebsitePlugin.ts +318 -0
  89. package/src/ts/server/backends/FsBackend.ts +266 -0
  90. package/src/ts/server/backends/index.ts +309 -0
  91. package/src/ts/server/cli.ts +0 -2
  92. package/src/ts/server/config.ts +103 -33
  93. package/src/ts/server/express.ts +37 -3
  94. package/src/ts/server/index.ts +24 -14
  95. package/src/ts/server/jobs.test.ts +74 -0
  96. package/src/ts/server/jobs.ts +77 -0
  97. package/src/ts/server/utils/validation.ts +33 -0
  98. package/src/ts/types.ts +167 -59
  99. package/dist/client/client/grapesjs/publish.d.ts +0 -18
  100. package/dist/page.js +0 -15
  101. package/src/plugins/AuthPlugin.js +0 -21
  102. package/src/plugins/Cache.js +0 -11
  103. package/src/plugins/DefaultBackend.js +0 -149
  104. package/src/plugins/ExpressPlugin.js +0 -39
  105. package/src/plugins/HooksPlugin.js +0 -58
  106. package/src/plugins/PublishPlugin.js +0 -69
  107. package/src/plugins/StaticPlugin.js +0 -48
  108. package/src/plugins/WebsitePlugin.js +0 -207
  109. package/src/ts/client/grapesjs/publish.ts +0 -403
  110. /package/.silex/default/{.silex.data.json → website.json} +0 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*
3
+ * Silex website builder, free/libre no-code tool for makers.
4
+ * Copyright (c) 2023 lexoyo and Silex Labs foundation
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const node_fetch_1 = __importDefault(require("node-fetch"));
23
+ const rootPath = process.env.DATA_FOLDER;
24
+ // **********
25
+ throw new Error('TODO: implement hooks plugin');
26
+ const EVENT_ASSET_WRITE_END = 'silex:asset:write:end';
27
+ const EVENT_PUBLISH_END = 'silex:publish:end';
28
+ const EVENT_WRITE_END = 'silex:write:end';
29
+ function projectPath(projectId) { return `${rootPath}/${projectId}`; }
30
+ // **********
31
+ async function default_1(config, opts = {}) {
32
+ // Options with defaults
33
+ const options = {
34
+ gitUrl: process.env.SILEX_HOOK_GIT,
35
+ buildUrl: process.env.SILEX_HOOK_BUILD,
36
+ ...opts
37
+ };
38
+ config.on(EVENT_WRITE_END, async ({ res, req, projectId, data }) => {
39
+ if (options.gitUrl) {
40
+ await hook(options.gitUrl, {
41
+ path: projectPath(projectId),
42
+ message: 'Change from Silex',
43
+ });
44
+ }
45
+ });
46
+ config.on(EVENT_ASSET_WRITE_END, async ({ res, req, projectId, uploadDir, form, data }) => {
47
+ if (options.gitUrl) {
48
+ await hook(options.gitUrl, {
49
+ path: projectPath(projectId),
50
+ message: 'Change from Silex',
51
+ });
52
+ }
53
+ });
54
+ config.on(EVENT_PUBLISH_END, async ({ projectId, files, req, res }) => {
55
+ if (options.buildUrl) {
56
+ await hook(options.buildUrl);
57
+ }
58
+ });
59
+ }
60
+ exports.default = default_1;
61
+ async function hook(url, params = {}) {
62
+ if (url) {
63
+ const urlObj = new URL(url);
64
+ console.log('Calling hook', { url });
65
+ try {
66
+ Object.keys(params)
67
+ .forEach(key => urlObj.searchParams.append(key, params[key]));
68
+ return (0, node_fetch_1.default)(urlObj.toString());
69
+ }
70
+ catch (error) {
71
+ console.log('Hook call failed', { url, error });
72
+ return null;
73
+ }
74
+ }
75
+ }
76
+ //# sourceMappingURL=HooksPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HooksPlugin.js","sourceRoot":"","sources":["../../src/ts/plugins/HooksPlugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;AAEH,4DAA8B;AAQ9B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAExC,aAAa;AACb,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;AAC/C,MAAM,qBAAqB,GAAG,uBAAuB,CAAA;AACrD,MAAM,iBAAiB,GAAG,mBAAmB,CAAA;AAC7C,MAAM,eAAe,GAAG,iBAAiB,CAAA;AACzC,SAAS,WAAW,CAAC,SAAiB,IAAI,OAAO,GAAG,QAAQ,IAAI,SAAS,EAAE,CAAA,CAAC,CAAC;AAC7E,aAAa;AAEE,KAAK,oBAAU,MAAoB,EAAE,OAAqB,EAAE;IACzE,wBAAwB;IACxB,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAClC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QACtC,GAAG,IAAI;KACR,CAAA;IACD,MAAM,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;QACjE,IAAG,OAAO,CAAC,MAAM,EAAE;YACjB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBACzB,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC;gBAC5B,OAAO,E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GAAG,EAAE,KAAK,EAAC,CAAC,CAAA;YAC7C,OAAO,IAAI,CAAA;SACZ;KACF;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { HostingProvider } from '../server/backends';
2
+ import { ServerConfig } from '../server/config';
3
+ /**
4
+ * Error thrown by the publication API
5
+ * @param message error message
6
+ * @param code http status code
7
+ */
8
+ export declare class PublicationError extends Error {
9
+ code: number;
10
+ constructor(message: string, code: number);
11
+ }
12
+ /**
13
+ * Get the desired backend
14
+ * Can be the default backend or a specific one
15
+ */
16
+ export declare function getHostingProvider(session: any, config: ServerConfig, backendId?: string): Promise<HostingProvider>;
17
+ export default function (config: ServerConfig, opts?: {}): Promise<void>;
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /*
3
+ * Silex website builder, free/libre no-code tool for makers.
4
+ * Copyright (c) 2023 lexoyo and Silex Labs foundation
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getHostingProvider = exports.PublicationError = void 0;
23
+ const express_1 = __importDefault(require("express"));
24
+ const Cache_1 = require("./Cache");
25
+ const html_minifier_1 = require("html-minifier");
26
+ const constants_1 = require("../constants");
27
+ const jobs_1 = require("../server/jobs");
28
+ const types_1 = require("../types");
29
+ const backends_1 = require("../server/backends");
30
+ const validation_1 = require("../server/utils/validation");
31
+ const events_1 = require("../events");
32
+ /**
33
+ * @fileoverview Publication plugin for Silex
34
+ * Adds a publication API to Silex server
35
+ */
36
+ const defaultPublication = {
37
+ url: '',
38
+ autoHomePage: true,
39
+ assets: { path: 'assets', url: '/assets' },
40
+ html: { path: '' },
41
+ css: { path: 'css', url: '/css' },
42
+ };
43
+ /**
44
+ * Error thrown by the publication API
45
+ * @param message error message
46
+ * @param code http status code
47
+ */
48
+ class PublicationError extends Error {
49
+ code;
50
+ constructor(message, code) {
51
+ super(message);
52
+ this.code = code;
53
+ }
54
+ }
55
+ exports.PublicationError = PublicationError;
56
+ /**
57
+ * Get the desired backend
58
+ * Can be the default backend or a specific one
59
+ */
60
+ async function getHostingProvider(session, config, backendId) {
61
+ const hostingProvider = await (0, backends_1.getBackend)(config, session, types_1.BackendType.HOSTING, backendId); // ?? config.getHostingProviders()[0]
62
+ if (!hostingProvider) {
63
+ throw new PublicationError('No hosting provider found', 404);
64
+ }
65
+ if (!await hostingProvider.isLoggedIn(session)) {
66
+ throw new PublicationError('Not logged in', 401);
67
+ }
68
+ return hostingProvider;
69
+ }
70
+ exports.getHostingProvider = getHostingProvider;
71
+ async function default_1(config, opts = {}) {
72
+ const options = {
73
+ // Defaults
74
+ statusUrl: process.env.SILEX_PUBLICATION_STATUS_URL,
75
+ backend: 'src/plugins/DefaultBackend.js',
76
+ // Options
77
+ ...opts,
78
+ };
79
+ config.on(events_1.EVENT_STARTUP_START, ({ app }) => {
80
+ const router = express_1.default.Router();
81
+ // Get publication status
82
+ router.get(`/${constants_1.API_PUBLICATION_STATUS}`, async function (req, res) {
83
+ const query = req.query;
84
+ const jobId = query.jobId;
85
+ const job = jobId && (0, jobs_1.getJob)(jobId);
86
+ if (!job) {
87
+ console.error(`Error: job not found with id ${jobId}`);
88
+ res.status(404).json({
89
+ message: 'Error: job not found.',
90
+ });
91
+ return;
92
+ }
93
+ res.json({
94
+ ...job,
95
+ _timeout: undefined,
96
+ });
97
+ });
98
+ // Publish website
99
+ router.post(`/${constants_1.API_PUBLICATION_PUBLISH}`, async function (req, res) {
100
+ try {
101
+ const query = req.query;
102
+ const body = req.body;
103
+ const id = (0, validation_1.requiredParam)(query.id, 'id in query');
104
+ const session = (0, validation_1.requiredParam)(req['session'], 'session on express request');
105
+ // Check params
106
+ const { files, publication } = body;
107
+ const publicationSettings = {
108
+ ...defaultPublication,
109
+ ...publication,
110
+ };
111
+ const backend = (0, validation_1.requiredParam)(publicationSettings.backend, 'backend object in publicationSettings');
112
+ const backendId = (0, validation_1.requiredParam)(backend.backendId, 'backendId in publicationSettings');
113
+ if (!files)
114
+ throw new PublicationError('Error in the request, files not found', 400);
115
+ // Get hosting provider and make sure the user is logged in
116
+ const hostingProvider = await getHostingProvider(session, config, backendId);
117
+ if (!hostingProvider)
118
+ throw new PublicationError('Error in the request, hosting provider not found', 400);
119
+ if (!hostingProvider.isLoggedIn(session))
120
+ throw new PublicationError(`You must be logged in with ${hostingProvider.displayName} to publish`, 401);
121
+ // Optim HTML
122
+ files.map(file => ({
123
+ ...file,
124
+ html: (0, html_minifier_1.minify)(file.html, {
125
+ continueOnParseError: true,
126
+ collapseInlineTagWhitespace: true,
127
+ collapseWhitespace: true,
128
+ minifyCSS: true,
129
+ minifyJS: true,
130
+ removeScriptTypeAttributes: true,
131
+ removeStyleLinkTypeAttributes: true,
132
+ }).trim(),
133
+ }));
134
+ // Publication
135
+ const filesList = files.flatMap(file => ([{
136
+ path: file.htmlPath,
137
+ content: file.html,
138
+ }, {
139
+ path: file.cssPath,
140
+ content: file.css,
141
+ }]));
142
+ try {
143
+ res.json({
144
+ url: await hostingProvider.getWebsiteUrl(session, id),
145
+ job: await hostingProvider.publish(session, id, backend, filesList),
146
+ });
147
+ }
148
+ catch (err) {
149
+ console.error('Error publishing the website', err);
150
+ res.status(500).json({
151
+ message: `Error publishing the website. ${err.message}`
152
+ });
153
+ return;
154
+ }
155
+ }
156
+ catch (err) {
157
+ console.error('Error publishing the website', err);
158
+ res
159
+ .status(err.code ?? 500)
160
+ .json({
161
+ message: `Error publishing the website. ${err.message}`
162
+ });
163
+ return;
164
+ }
165
+ });
166
+ app.use(Cache_1.noCache, router);
167
+ });
168
+ }
169
+ exports.default = default_1;
170
+ //# sourceMappingURL=PublicationPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PublicationPlugin.js","sourceRoot":"","sources":["../../src/ts/plugins/PublicationPlugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;AAEH,sDAA6B;AAC7B,mCAAiC;AACjC,iDAAsC;AACtC,4CAA8E;AAC9E,yCAAuC;AACvC,oCAAoS;AACpS,iDAAgE;AAEhE,2DAA0D;AAC1D,sCAA+C;AAE/C;;;GAGG;AAEH,MAAM,kBAAkB,GAAwB;IAC9C,GAAG,EAAE,EAAE;IACP,YAAY,EAAE,IAAI;IAClB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE;IAC1C,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;IAClB,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE;CAClC,CAAA;AAED;;;;GAIG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACL;IAApC,YAAY,OAAe,EAAS,IAAY;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QADoB,SAAI,GAAJ,IAAI,CAAQ;IAEhD,CAAC;CACF;AAJD,4CAIC;AAED;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAY,EAAE,MAAoB,EAAE,SAAkB;IAC7F,MAAM,eAAe,GAAG,MAAM,IAAA,qBAAU,EAAC,MAAM,EAAE,OAAO,EAAE,mBAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA,CAAC,sCAAsC;IAEhI,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,IAAI,gBAAgB,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;KAC7D;IAED,IA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,CAAC,CAAA;gBACxB,OAAM;aACP;QACH,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,GAAG,CAAC,eAAO,EAAG,MAAM,CAAC,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC;AAnGD,4BAmGC"}
@@ -0,0 +1 @@
1
+ export default function (config: any, opts?: {}): Promise<void>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /*
3
+ * Silex website builder, free/libre no-code tool for makers.
4
+ * Copyright (c) 2023 lexoyo and Silex Labs foundation
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const express_1 = __importDefault(require("express"));
23
+ const fs_1 = require("fs");
24
+ const https_1 = require("https");
25
+ const express_force_ssl_1 = __importDefault(require("express-force-ssl"));
26
+ const events_1 = require("../events");
27
+ // interface SslOptions {
28
+ // forceHttps?: boolean
29
+ // trustXFPHeader?: boolean
30
+ // privateKey?: string
31
+ // certificate?: string
32
+ // sslPort?: string
33
+ // }
34
+ async function default_1(config, opts = {}) {
35
+ // Options with defaults
36
+ const options = {
37
+ forceHttps: process.env.SILEX_FORCE_HTTPS === 'true',
38
+ trustXFPHeader: process.env.SILEX_FORCE_HTTPS_TRUST_XFP_HEADER === 'true',
39
+ privateKey: process.env.SILEX_SSL_PRIVATE_KEY,
40
+ certificate: process.env.SILEX_SSL_CERTIFICATE,
41
+ sslPort: process.env.SSL_PORT || '443',
42
+ ...opts,
43
+ };
44
+ // Add routes on silex startup
45
+ config.on(events_1.EVENT_STARTUP_START, ({ app }) => {
46
+ const router = express_1.default.Router();
47
+ // SSL
48
+ // force ssl if the env var SILEX_FORCE_HTTPS is set
49
+ if (options.forceHttps) {
50
+ console.log('> Force SSL option is enabled');
51
+ app.set('forceSSLOptions', {
52
+ trustXFPHeader: !!options.trustXFPHeader,
53
+ });
54
+ router.use(express_force_ssl_1.default);
55
+ }
56
+ else {
57
+ console.log('> Force SSL option is disabled, env var SILEX_FORCE_HTTPS not set');
58
+ }
59
+ // SSL certificate
60
+ if (options.privateKey && options.certificate) {
61
+ console.log('> SSL certificate is enabled, found certificate:', options.certificate);
62
+ try {
63
+ const privateKey = (0, fs_1.readFileSync)(options.privateKey).toString();
64
+ const certificate = (0, fs_1.readFileSync)(options.certificate).toString();
65
+ const sslServerOptions = {
66
+ key: privateKey,
67
+ cert: certificate,
68
+ requestCert: true,
69
+ rejectUnauthorized: false,
70
+ };
71
+ (0, https_1.createServer)(sslServerOptions, this).listen(options.sslPort, () => {
72
+ console.log('SSL: listening on port ', options.sslPort);
73
+ });
74
+ }
75
+ catch (e) {
76
+ console.error('SSL: load certificate failed.', e);
77
+ }
78
+ }
79
+ else {
80
+ console.log('> SSL certificate disabled, env vars SILEX_SSL_CERTIFICATE and SILEX_SSL_PRIVATE_KEY not set');
81
+ }
82
+ app.use(router);
83
+ });
84
+ }
85
+ exports.default = default_1;
86
+ //# sourceMappingURL=SslPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SslPlugin.js","sourceRoot":"","sources":["../../src/ts/plugins/SslPlugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;AAEH,sDAA6B;AAC7B,2BAAiC;AACjC,iCAAoC;AACpC,0EAAwC;AACxC,sCAA+C;AAE/C,yBAAyB;AACzB,yBAAyB;AACzB,6BAA6B;AAC7B,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AA,iBAAY,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA;gBAEhE,MAAM,gBAAgB,GAAG;oBACvB,GAAG,EAAE,UAAU;oBACf,IAAI,EAAE,WAAW;oBACjB,WAAW,EAAE,IAAI;oBACjB,kBAAkB,EAAE,KAAK;iBAC1B,CAAA;gBAED,IAAA,oBAAY,EAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE;oBAChE,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;gBACzD,CAAC,CAAC,CAAA;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAA;aAClD;SACF;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,8FAA8F,CAAC,CAAA;SAC5G;QACD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC;AApDD,4BAoDC"}
@@ -0,0 +1 @@
1
+ export default function (config: any, opts?: {}): Promise<void>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /*
3
+ * Silex website builder, free/libre no-code tool for makers.
4
+ * Copyright (c) 2023 lexoyo and Silex Labs foundation
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const express_1 = __importDefault(require("express"));
23
+ const node_modules_path_1 = __importDefault(require("node_modules-path"));
24
+ const serve_static_1 = __importDefault(require("serve-static"));
25
+ const Cache_1 = require("./Cache");
26
+ const events_1 = require("../events");
27
+ async function default_1(config, opts = {}) {
28
+ // Options with defaults
29
+ const options = {
30
+ routes: [
31
+ {
32
+ route: '/',
33
+ path: 'public',
34
+ }, {
35
+ route: '/css/',
36
+ path: (0, node_modules_path_1.default)('@fortawesome/fontawesome-free') + '/@fortawesome/fontawesome-free/css/',
37
+ }, {
38
+ route: '/webfonts/',
39
+ path: (0, node_modules_path_1.default)('@fortawesome/fontawesome-free') + '/@fortawesome/fontawesome-free/webfonts/',
40
+ }, {
41
+ route: '/',
42
+ path: 'dist/client',
43
+ },
44
+ ]
45
+ // add project route for source maps
46
+ .concat(config.debug ? [{
47
+ route: '/',
48
+ path: './',
49
+ }] : []),
50
+ ...opts,
51
+ };
52
+ config.on(events_1.EVENT_STARTUP_START, ({ app }) => {
53
+ const router = express_1.default.Router();
54
+ options.routes
55
+ .forEach(folder => {
56
+ if (!folder.route)
57
+ throw new Error('The config for static module has no `route` attribute');
58
+ if (!folder.path)
59
+ throw new Error('The config for static module has no `path` attribute');
60
+ router.use(folder.route, (0, serve_static_1.default)(folder.path));
61
+ });
62
+ app.use(Cache_1.withCache, router);
63
+ });
64
+ }
65
+ exports.default = default_1;
66
+ //# sourceMappingURL=StaticPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaticPlugin.js","sourceRoot":"","sources":["../../src/ts/plugins/StaticPlugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;AAEH,sDAA6B;AAC7B,0EAA2C;AAC3C,gEAAsC;AACtC,mCAAmC;AAEnC,sCAA+C;AAShC,KAAK,oBAAU,MAAM,EAAE,IAAI,GAAG,EAAE;IAC7C,wBAAwB;IACxB,MA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3
+ * This plugin provides the website API to Silex server
4
+ */
5
+ /**
6
+ * Error thrown by the website API
7
+ * @param message error message
8
+ * @param code http status code
9
+ */
10
+ export declare class WebsiteError extends Error {
11
+ code: number;
12
+ constructor(message: string, code: number);
13
+ }
14
+ export default function (config: any, opts?: {}): Promise<void>;