@silexlabs/silex 3.0.0-alpha.30 → 3.0.1-alpha.0

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 (42) hide show
  1. package/.silex/default/.silex.data.json +1 -0
  2. package/.silex.js +1 -8
  3. package/CONTRIBUTING.md +48 -25
  4. package/README.md +96 -0
  5. package/dist/client/css/admin.css +4 -66
  6. package/dist/client/js/main.js +53 -103
  7. package/dist/client/js/main.js.LICENSE.txt +3 -19
  8. package/dist/constants.js +4 -0
  9. package/dist/page.js +15 -0
  10. package/dist/server/cli.js +9 -0
  11. package/dist/server/config.js +31 -11
  12. package/dist/server/{start.js → express.js} +1 -1
  13. package/dist/server/index.js +9 -3
  14. package/dist/types.js +34 -0
  15. package/package.json +35 -34
  16. package/public/silex.js +25 -0
  17. package/src/example-client-config.js +47 -0
  18. package/src/plugins/DefaultBackend.js +40 -4
  19. package/src/plugins/ExpressPlugin.js +9 -0
  20. package/src/plugins/PublishPlugin.js +4 -4
  21. package/src/plugins/WebsitePlugin.js +77 -18
  22. package/src/ts/client/config.ts +20 -2
  23. package/src/ts/client/grapesjs/blocks.ts +18 -86
  24. package/src/ts/client/grapesjs/index.ts +27 -9
  25. package/src/ts/client/grapesjs/internal-links.test.ts +1 -0
  26. package/src/ts/client/grapesjs/publish.ts +4 -4
  27. package/src/ts/client/grapesjs/semantic.ts +1 -0
  28. package/src/ts/client/index.ts +21 -8
  29. package/src/ts/constants.ts +5 -0
  30. package/src/ts/server/cli.ts +6 -0
  31. package/src/ts/server/config.ts +45 -16
  32. package/src/ts/server/{start.ts → express.ts} +1 -1
  33. package/src/ts/server/index.ts +9 -2
  34. package/src/ts/types.ts +6 -12
  35. package/tsconfig-server-debug.json +2 -3
  36. package/tsconfig-server-release.json +2 -3
  37. package/tsconfig.json +2 -3
  38. package/webpack.config.js +0 -1
  39. package/public/example-config.js +0 -31
  40. package/readme.md +0 -51
  41. /package/dist/{server/events.js → events.js} +0 -0
  42. /package/src/ts/{server/events.ts → events.ts} +0 -0
@@ -1,31 +1,15 @@
1
1
  /*!
2
- * Sizzle CSS Selector Engine v2.3.10
3
- * https://sizzlejs.com/
4
- *
5
- * Copyright JS Foundation and other contributors
6
- * Released under the MIT license
7
- * https://js.foundation/
8
- *
9
- * Date: 2023-02-14
10
- */
11
-
12
- /*!
13
- * jQuery JavaScript Library v3.6.4
2
+ * jQuery JavaScript Library v3.7.0
14
3
  * https://jquery.com/
15
4
  *
16
- * Includes Sizzle.js
17
- * https://sizzlejs.com/
18
- *
19
5
  * Copyright OpenJS Foundation and other contributors
20
6
  * Released under the MIT license
21
7
  * https://jquery.org/license
22
8
  *
23
- * Date: 2023-03-08T15:28Z
9
+ * Date: 2023-05-11T18:29Z
24
10
  */
25
11
 
26
- /*! @silexlabs/grapesjs-loading - 1.0.7 */
27
-
28
- /*! grapesjs-style-filter - 1.0.1 */
12
+ /*! @silexlabs/grapesjs-loading - 1.0.8 */
29
13
 
30
14
  /**
31
15
  * @license
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLIENT_CONFIG_FILE_NAME = void 0;
4
+ exports.CLIENT_CONFIG_FILE_NAME = 'silex.js';
package/dist/page.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPageLink = exports.getPageSlug = void 0;
4
+ function getPageSlug(pageName = 'index') {
5
+ return pageName
6
+ .toLowerCase()
7
+ .replace(/[^a-z0-9 -]/g, '')
8
+ .replace(/\s+/g, '-')
9
+ .replace(/-+/g, '-');
10
+ }
11
+ exports.getPageSlug = getPageSlug;
12
+ function getPageLink(pageName = 'index') {
13
+ return `./${getPageSlug(pageName)}.html`;
14
+ }
15
+ exports.getPageLink = getPageLink;
@@ -12,6 +12,9 @@ const options = (0, cli_1.parse)({
12
12
  'ssl-certificate': [false, 'Path to SSL certificate', 'file'],
13
13
  'force-https-trust-xfp-header': [false, 'Sets the trustXFPHeader param of the express module "cookie-session". Use only with --force-https', 'boolean'],
14
14
  'session-secret': ['s', 'Session secret', 'string'],
15
+ 'cors-url': ['', 'Enable CORS for URL (can be "*")', 'string'],
16
+ 'client-config': ['', 'Path to client config file to be served on .silex-client.js', 'string'],
17
+ 'fs-root': ['', 'Path to the root folder where to store websites. Used by the default backend (fs).', 'string'],
15
18
  }, {});
16
19
  if (options.config)
17
20
  process.env.CONFIG = options.config;
@@ -31,4 +34,10 @@ if (options['force-https-trust-xfp-header'])
31
34
  process.env.SILEX_FORCE_HTTPS_TRUST_XFP_HEADER = options['force-https-trust-xfp-header'];
32
35
  if (options['session-secret'])
33
36
  process.env.SILEX_SESSION_SECRET = options['session-secret'];
37
+ if (options['cors-url'])
38
+ process.env.SILEX_CORS_URL = options['cors-url'];
39
+ if (options['client-config'])
40
+ process.env.SILEX_CLIENT_CONFIG = options['client-config'];
41
+ if (options['fs-root'])
42
+ process.env.FS_ROOT = options['fs-root'];
34
43
  require("./index");
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServerConfig = void 0;
4
4
  const silex_plugins_1 = require("@silexlabs/silex-plugins");
5
5
  const path_1 = require("path");
6
+ const constants_1 = require("../constants");
7
+ const express_1 = require("express");
8
+ const promises_1 = require("fs/promises");
9
+ const events_1 = require("../events");
6
10
  class ServerConfig extends silex_plugins_1.Config {
7
11
  url;
8
12
  debug;
@@ -20,10 +24,36 @@ exports.ServerConfig = ServerConfig;
20
24
  async function default_1() {
21
25
  const port = process.env.PORT || '6805';
22
26
  const debug = process.env.SILEX_DEBUG === 'true';
27
+ const clientConfigPath = process.env.SILEX_CLIENT_CONFIG;
23
28
  const url = process.env.SERVER_URL || `http://localhost:${port}`;
24
29
  const config = new ServerConfig(url, debug, port, '/api');
30
+ if (clientConfigPath) {
31
+ config.on(events_1.EVENT_STARTUP_START, async ({ app }) => {
32
+ console.log(`> Serving client side config ${clientConfigPath} at ${constants_1.CLIENT_CONFIG_FILE_NAME}`);
33
+ const router = (0, express_1.Router)();
34
+ app.use(router);
35
+ let clientConfig = (await (0, promises_1.readFile)(clientConfigPath)).toString();
36
+ router.get(`/${constants_1.CLIENT_CONFIG_FILE_NAME}`, async (res, req, next) => {
37
+ if (config.debug) {
38
+ console.log('[Debug mode] Reloading config file', clientConfigPath);
39
+ clientConfig = (await (0, promises_1.readFile)(clientConfigPath)).toString();
40
+ }
41
+ req.header('Content-Type', 'application/javascript').send(clientConfig);
42
+ });
43
+ });
44
+ }
45
+ if (process.env.CONFIG) {
46
+ const userConfigPath = process.env.CONFIG;
47
+ console.log('> Loading user config', userConfigPath);
48
+ try {
49
+ await config.addPlugin(userConfigPath, {});
50
+ }
51
+ catch (e) {
52
+ throw new Error(`User config file ${userConfigPath} error: ${e.message}`);
53
+ }
54
+ }
25
55
  const configFilePath = (0, path_1.resolve)(__dirname, '../../.silex.js');
26
- console.log('Loading config', configFilePath);
56
+ console.log('> Loading config', configFilePath);
27
57
  try {
28
58
  await config.addPlugin(configFilePath, {});
29
59
  }
@@ -35,16 +65,6 @@ async function default_1() {
35
65
  throw new Error(`Error in config file ${configFilePath}: ${e.message}`);
36
66
  }
37
67
  }
38
- if (process.env.CONFIG) {
39
- const userConfigPath = process.env.CONFIG;
40
- console.log('Loading user config', userConfigPath);
41
- try {
42
- await config.addPlugin(userConfigPath, {});
43
- }
44
- catch (e) {
45
- throw new Error(`User config file ${userConfigPath} not found: ${e.message}`);
46
- }
47
- }
48
68
  return config;
49
69
  }
50
70
  exports.default = default_1;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const express_1 = __importDefault(require("express"));
7
- const events_1 = require("./events");
7
+ const events_1 = require("../events");
8
8
  async function default_1(config) {
9
9
  const app = (0, express_1.default)();
10
10
  await config.emit(events_1.EVENT_STARTUP_START, { app });
@@ -27,10 +27,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const config_1 = __importDefault(require("./config"));
30
- const start_1 = __importDefault(require("./start"));
30
+ const express_1 = __importDefault(require("./express"));
31
+ const config = __importStar(require("./config"));
32
+ const types = __importStar(require("../types"));
33
+ const events = __importStar(require("../events"));
34
+ const constants = __importStar(require("../constants"));
35
+ const page = __importStar(require("../page"));
36
+ exports.default = { config, types, events, constants, page };
31
37
  async function main() {
32
38
  const config = await (0, config_1.default)();
33
- const app = await (0, start_1.default)(config);
39
+ const app = await (0, express_1.default)(config);
34
40
  console.info(`
35
41
  I'm ready, listening to port ${config.port}
36
42
  `);
@@ -46,7 +52,7 @@ async function startLiverReload() {
46
52
  const server = createServer({
47
53
  delay: 0,
48
54
  }, () => {
49
- console.info(`\nDebug mode\nLive reload server is running.\nWatching ${dist}`);
55
+ console.info(`\n> Debug mode\n> Live reload server is running.\n> Watching ${dist}`);
50
56
  });
51
57
  server.watch(dist);
52
58
  }
package/dist/types.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Unit = exports.defaultSite = exports.defaultPublicationSettings = void 0;
4
+ exports.defaultPublicationSettings = {
5
+ path: 'publication',
6
+ url: '',
7
+ autoHomePage: true,
8
+ assets: { path: 'assets', url: '/assets' },
9
+ html: { path: '' },
10
+ css: { path: 'css', url: '/css' },
11
+ };
12
+ exports.defaultSite = {
13
+ pages: [{ name: 'Main', id: 'main', frames: [{ component: { type: 'text', stylable: [] }, components: [] }] }],
14
+ assets: [],
15
+ styles: [],
16
+ name: 'New website',
17
+ settings: {
18
+ description: '',
19
+ title: '',
20
+ head: '',
21
+ lang: '',
22
+ favicon: '',
23
+ 'og:title': '',
24
+ 'og:description': '',
25
+ 'og:image': '',
26
+ },
27
+ fonts: [],
28
+ symbols: [],
29
+ publication: exports.defaultPublicationSettings,
30
+ };
31
+ var Unit;
32
+ (function (Unit) {
33
+ Unit["PX"] = "px";
34
+ })(Unit || (exports.Unit = Unit = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silexlabs/silex",
3
3
  "description": "Free and easy website builder for everyone.",
4
- "version": "3.0.0-alpha.30",
4
+ "version": "3.0.1-alpha.0",
5
5
  "version:backwardcompat": "3.0.0",
6
6
  "author": {
7
7
  "name": "Alex Hoyau",
@@ -52,9 +52,9 @@
52
52
  "release": "",
53
53
  "watch": "npm-watch",
54
54
  "start": "node dist/server/index.js",
55
- "start:debug": "cross-env SILEX_DEBUG=true nodemon --watch dist/server dist/server/index.js",
56
- "prepublishOnly": "npm run lint && npm test && npm run build",
57
- "preversion": "npm run prepublishOnly",
55
+ "start:debug": "cross-env FS_ROOT=`pwd`/.silex cross-env SILEX_DEBUG=true nodemon --watch dist/server dist/server/index.js",
56
+ "prepublishOnly": "$npm_execpath run lint && $npm_execpath test && $npm_execpath run build",
57
+ "preversion": "$npm_execpath run prepublishOnly",
58
58
  "build": "run-s build:css:release build:html build:client:release build:server:release",
59
59
  "webpack": "webpack --config webpack.config.js",
60
60
  "build:css:release": "sass --load-path ../../node_modules --load-path node_modules --no-source-map src/css/index.scss dist/client/css/admin.css",
@@ -66,66 +66,67 @@
66
66
  "build:server:release": "tsc -p tsconfig-server-release.json",
67
67
  "build:server:debug": "SILEX_DEBUG=true tsc -p tsconfig-server-debug.json",
68
68
  "lint": "eslint 'src/ts/**/*.ts'",
69
- "lint:fix": "npm run lint -- --fix",
69
+ "lint:fix": "$npm_execpath run lint -- --fix",
70
70
  "test": "node --experimental-vm-modules `node_modules jest`/jest/bin/jest.js",
71
- "test:watch": "npm test -- --watch"
71
+ "test:watch": "$npm_execpath test -- --watch"
72
72
  },
73
73
  "dependencies": {
74
- "@directus/sdk": "^10.3.3",
74
+ "@directus/sdk": "10.3.3",
75
75
  "@silexlabs/grapesjs-directus-storage": "1.0.15",
76
76
  "@silexlabs/grapesjs-fonts": "1.0.12",
77
- "@silexlabs/grapesjs-loading": "1.0.7",
78
- "@silexlabs/grapesjs-symbols": "1.0.18",
77
+ "@silexlabs/grapesjs-loading": "1.0.8",
78
+ "@silexlabs/grapesjs-symbols": "1.0.20",
79
79
  "@silexlabs/grapesjs-ui-suggest-classes": "1.0.23",
80
- "@silexlabs/silex-plugins": "^1.0.6",
80
+ "@silexlabs/silex-plugins": "1.0.10",
81
81
  "adm-zip": "0.5.10",
82
82
  "body-parser": "1.20.2",
83
- "cli": "^1.0.1",
83
+ "cli": "1.0.1",
84
84
  "compression": "1.7.4",
85
85
  "cookie-parser": "1.4.6",
86
86
  "cookie-session": "2.0.0",
87
+ "cors": "2.8.5",
87
88
  "cross-env": "7.0.3",
88
89
  "express": "4.18.2",
89
90
  "express-force-ssl": "0.3.2",
90
91
  "formidable": "2.1.1",
91
- "grapesjs": "0.21.1",
92
- "grapesjs-blocks-basic": "1.0.1",
93
- "grapesjs-custom-code": "1.0.1",
94
- "grapesjs-plugin-forms": "2.0.5",
95
- "grapesjs-style-filter": "1.0.1",
96
- "html-minifier": "^4.0.0",
97
- "lit-html": "2.7.2",
92
+ "grapesjs": "0.21.2",
93
+ "grapesjs-blocks-basic": "1.0.2",
94
+ "grapesjs-custom-code": "1.0.2",
95
+ "grapesjs-plugin-forms": "2.0.6",
96
+ "grapesjs-style-filter": "1.0.2",
97
+ "html-minifier": "4.0.0",
98
+ "lit-html": "2.7.4",
98
99
  "mkdirp": "3.0.1",
99
100
  "node_modules-path": "2.0.7",
100
- "node-fetch": "^2.6.9",
101
+ "node-fetch": "2.6.9",
101
102
  "normalize.css": "8.0.1",
102
103
  "object-path": "0.11.8",
103
104
  "promise-sequential": "1.1.1",
104
- "sass": "1.62.0",
105
+ "sass": "1.63.6",
105
106
  "serve-static": "1.15.0"
106
107
  },
107
108
  "devDependencies": {
108
109
  "@types/express": "4.17.17",
109
- "@types/jest": "29.5.1",
110
- "@types/node": "18.16.0",
111
- "@typescript-eslint/eslint-plugin": "^5.59.1",
112
- "@typescript-eslint/parser": "^5.59.1",
113
- "css-loader": "6.7.3",
114
- "eslint": "8.39.0",
110
+ "@types/jest": "29.5.2",
111
+ "@types/node": "20.3.1",
112
+ "@typescript-eslint/eslint-plugin": "5.60.0",
113
+ "@typescript-eslint/parser": "5.60.0",
114
+ "css-loader": "6.8.1",
115
+ "eslint": "8.43.0",
115
116
  "file-loader": "6.2.0",
116
117
  "jest": "29.5.0",
117
- "jest-environment-jsdom": "^29.5.0",
118
- "livereload": "^0.9.3",
118
+ "jest-environment-jsdom": "29.5.0",
119
+ "livereload": "0.9.3",
119
120
  "nodemon": "2.0.22",
120
121
  "npm-run-all": "4.1.5",
121
122
  "npm-watch": "0.11.0",
122
123
  "pug-cli": "1.0.0-alpha6",
123
- "style-loader": "3.3.2",
124
- "ts-jest": "^29.1.0",
125
- "ts-loader": "9.4.2",
126
- "typescript": "5.0.4",
127
- "webpack": "5.80.0",
128
- "webpack-cli": "5.0.2"
124
+ "style-loader": "3.3.3",
125
+ "ts-jest": "29.1.0",
126
+ "ts-loader": "9.4.3",
127
+ "typescript": "5.1.3",
128
+ "webpack": "5.88.0",
129
+ "webpack-cli": "5.1.4"
129
130
  },
130
131
  "repository": {
131
132
  "type": "git",
@@ -0,0 +1,25 @@
1
+ // This file is loaded by Silex when the user opens the editor
2
+ // Unless you override the default config with the environment variable SILEX_CLIENT_CONFIG or the CLI option --client-config
3
+ export default async function (config) {
4
+ // // For example add a GrapesJs plugin like this
5
+ // config.editor.plugins.push(plugin)
6
+ // config.editor.pluginsOpts[plugin] = {
7
+ // }
8
+ // // Or like this to override the default options
9
+ // // See the docs for the list of options
10
+ // return {
11
+ // ...config,
12
+ // editor: {
13
+ // ...config.editor,
14
+ // plugins: [
15
+ // ...config.editor.plugins,
16
+ // plugin,
17
+ // ],
18
+ // pluginsOpts: {
19
+ // ...config.editor.pluginsOpts,
20
+ // [plugin]: {
21
+ // },
22
+ // },
23
+ // },
24
+ // }
25
+ }
@@ -0,0 +1,47 @@
1
+ import directusStorage from 'https://unpkg.com/@silexlabs/grapesjs-directus-storage'
2
+ console.log('directusStorage', directusStorage, directusStorage?.default)
3
+
4
+ // Use the environment variable SILEX_CLIENT_CONFIG or the CLI option --client-config to override the default config with this file
5
+ export default async function (config, options) {
6
+ console.log('In example config')
7
+ //await config.addPlugin('gjs-blocks-basic', 'https://unpkg.com/grapesjs-blocks-basic', {
8
+ // blocks: ['text', 'image', 'video', 'map'],
9
+ //})
10
+
11
+ // Optional plugins
12
+ await config.addPlugin([
13
+ '@silexlabs/grapesjs-directus-storage',
14
+ './plugins/@silexlabs/grapesjs-directus-storage/dist/index.js',
15
+ ], {
16
+ '@silexlabs/grapesjs-directus-storage': {
17
+ directusUrl: 'http://localhost:8055',
18
+ },
19
+ './plugins/@silexlabs/grapesjs-directus-storage/dist/index.js': {
20
+ directusUrl: 'http://localhost:8055',
21
+ },
22
+ })
23
+
24
+ // Return an object to override default config
25
+ return {
26
+ ...config,
27
+ ...options,
28
+ editor: {
29
+ ...config.editor,
30
+ storageManager: {
31
+ autoload: false,
32
+ type: 'directus',
33
+ },
34
+ plugins: [
35
+ ...config.editor.plugins,
36
+ directusStorage,
37
+ ],
38
+ pluginsOpts: {
39
+ ...config.editor.pluginsOpts,
40
+ [directusStorage]: {
41
+ directusUrl: 'http://localhost:8055',
42
+ },
43
+ },
44
+ },
45
+ }
46
+ }
47
+
@@ -1,4 +1,4 @@
1
- const { readFile, writeFile, mkdir, copyFile } = require('node:fs/promises')
1
+ const { readFile, writeFile, mkdir, copyFile, readdir, stat, rm } = require('node:fs/promises')
2
2
  const { join, dirname, basename } = require('path')
3
3
  const { homedir } = require('os')
4
4
 
@@ -20,8 +20,6 @@ async function mkdirIfNotExists(path, options = null) {
20
20
  const FS_ROOT = process.env.FS_ROOT || join(homedir(), '.silex')
21
21
  const ASSETS_PATH = 'assets'
22
22
  const ASSETS_URL = 'assets'
23
- const HTML_PATH = ''
24
- const CSS_PATH = ''
25
23
  const DATA_FILE_NAME = '/.silex.data.json'
26
24
  const PUBLICATION_PATH = 'publication'
27
25
 
@@ -45,9 +43,47 @@ exports.init = async function (id) {
45
43
  await mkdirIfNotExists(uploadDir, { recursive: true, })
46
44
  }
47
45
 
46
+ exports.del = async function (id) {
47
+ const folder = path(id)
48
+ console.log('Delete', folder)
49
+ await rm(folder, {recursive: true})
50
+ return {ok: true}
51
+ }
52
+
53
+ // List projects
54
+ exports.list = async function () {
55
+ try {
56
+ const ids = await readdir(FS_ROOT)
57
+ return Promise.all(ids.map(async id => ({
58
+ id,
59
+ ...await exports.readData(id),
60
+ stats: await stat(path(id) + DATA_FILE_NAME),
61
+ })))
62
+ } catch (error) {
63
+ if (error.code === 'ENOENT') {
64
+ console.log(`\nError: Directory ${FS_ROOT} does not exist.\nIf your want to read from a different folder ues the FS_ROOT environment variable or --fs-root command line argument?\n`);
65
+ const betterError = new Error(`The directory ${FS_ROOT} does not exist`)
66
+ betterError.code = 'ENOENT'
67
+ throw betterError
68
+ }
69
+ throw error
70
+ }
71
+ }
48
72
  // Read project data
49
73
  exports.readData = async function (id) {
50
- return readFile(path(id) + DATA_FILE_NAME)
74
+ const filePath = path(id) + DATA_FILE_NAME
75
+ try {
76
+ const data = await readFile(filePath)
77
+ return JSON.parse(data.toString())
78
+ } catch (error) {
79
+ if (error.code === 'ENOENT') {
80
+ console.log(`\nError: File ${filePath} or directory ${FS_ROOT} do not exist.\nIf your want to read from a different folder use the FS_ROOT environment variable or --fs-root command line argument?\n`);
81
+ const betterError = new Error(`The website ${id} does not exist`)
82
+ betterError.code = 'ENOENT'
83
+ throw betterError
84
+ }
85
+ throw error
86
+ }
51
87
  }
52
88
  // Write project data
53
89
  exports.writeData = async function (id, data) {
@@ -2,6 +2,7 @@ const bodyParser = require('body-parser')
2
2
  const compression = require('compression')
3
3
  const cookieParser = require('cookie-parser')
4
4
  const session = require('cookie-session')
5
+ const cors = require('cors')
5
6
 
6
7
  module.exports = async function(config, opts = {}) {
7
8
  // Options with defaults
@@ -10,10 +11,18 @@ module.exports = async function(config, opts = {}) {
10
11
  textLimit: process.env.SILEX_EXPRESS_TEXT_LIMIT || '10mb',
11
12
  sessionName: process.env.SILEX_SESSION_NAME || 'silex-session',
12
13
  sessionSecret: process.env.SILEX_SESSION_SECRET || 'replace this session secret in env vars',
14
+ cors: process.env.SILEX_CORS_URL,
13
15
  ...opts,
14
16
  }
15
17
 
16
18
  config.on('silex:startup:start', ({app}) => {
19
+ // CORS
20
+ if (options.cors) {
21
+ console.log('> CORS are ENABLED:', options.cors)
22
+ app.use(cors({
23
+ origin: options.cors,
24
+ }))
25
+ }
17
26
  // compress gzip when possible
18
27
  app.use(compression())
19
28
 
@@ -28,9 +28,9 @@ module.exports = async function(config, opts = {}) {
28
28
  router.post('/publish', async function(req, res) {
29
29
  const { pages, files, id } = req.body.data
30
30
  if (!pages || !id) {
31
- console.error('Error in the request, pages and id parmas required', {id})
31
+ console.error('Error in the request, pages and id params required', {id})
32
32
  res.status(400).send({
33
- message: 'Error in the request, pages and id parmas required',
33
+ message: 'Error in the request, pages and id params required',
34
34
  })
35
35
  } else {
36
36
  // Optim
@@ -46,7 +46,7 @@ module.exports = async function(config, opts = {}) {
46
46
  }).trim()
47
47
  })
48
48
  // Publication
49
- await config.emit(EVENT_PUBLISH_START, { id, files, req})
49
+ await config.emit('silex:publish:start', { id, files, req})
50
50
  let url
51
51
  try {
52
52
  url = await publish(id, files, req.body.data)
@@ -56,7 +56,7 @@ module.exports = async function(config, opts = {}) {
56
56
  return
57
57
  }
58
58
  const mutable = { id, files, req, res, url, statusUrl: options.statusUrl }
59
- await config.emit(EVENT_PUBLISH_END, mutable)
59
+ await config.emit('silex:publish:end', mutable)
60
60
  res.json({
61
61
  url: mutable.url,
62
62
  statusUrl: mutable.statusUrl,