catalyst-core 0.0.1-beta.4 → 0.0.1-beta.6

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 (92) hide show
  1. package/babel.config.json +1 -0
  2. package/bin/catalyst.js +2 -5
  3. package/changelog.md +14 -22
  4. package/dist/caching.js +1 -0
  5. package/dist/index.js +1 -0
  6. package/dist/logger.js +10 -0
  7. package/dist/router/ClientRouter.js +3 -0
  8. package/dist/router/ServerRouter.js +1 -0
  9. package/dist/router.js +1 -0
  10. package/dist/scripts/build.js +10 -0
  11. package/dist/scripts/centralImport.js +1 -0
  12. package/dist/scripts/checkVersion.js +1 -0
  13. package/dist/scripts/devBuild.js +10 -0
  14. package/dist/scripts/devServe.js +5 -0
  15. package/dist/scripts/loadEnvironmentVariables.js +5 -0
  16. package/dist/scripts/loadScriptsBeforeServerStarts.js +4 -0
  17. package/dist/scripts/registerAliases.js +2 -0
  18. package/dist/scripts/scriptUtils.js +2 -0
  19. package/dist/scripts/serve.js +5 -0
  20. package/dist/scripts/start.js +6 -0
  21. package/dist/scripts/validator.js +1 -0
  22. package/dist/server/expressServer.js +9 -0
  23. package/dist/server/renderer/document/Body.js +14 -0
  24. package/dist/server/renderer/document/Head.js +9 -0
  25. package/dist/server/renderer/document/index.js +1 -0
  26. package/dist/server/renderer/extract.js +21 -0
  27. package/dist/server/renderer/handler.js +17 -0
  28. package/dist/server/renderer/index.js +1 -0
  29. package/dist/server/renderer/render.js +21 -0
  30. package/dist/server/startServer.js +6 -0
  31. package/dist/server/utils/userAgentUtil.js +9 -0
  32. package/dist/server/utils/validator.js +1 -0
  33. package/dist/webpack/babel-plugins/remove-client.plugin.js +5 -0
  34. package/dist/webpack/babel-plugins/remove-ssr.plugin.js +5 -0
  35. package/dist/webpack/babel.config.client.js +1 -0
  36. package/dist/webpack/babel.config.ssr.js +1 -0
  37. package/dist/webpack/base.babel.js +8 -0
  38. package/dist/webpack/development.client.babel.js +4 -0
  39. package/dist/webpack/production.client.babel.js +4 -0
  40. package/dist/webpack/production.ssr.babel.js +4 -0
  41. package/dist/webpack/scssParams.js +9 -0
  42. package/package.json +109 -87
  43. package/.eslintignore +0 -9
  44. package/.eslintrc +0 -92
  45. package/caching.js +0 -16
  46. package/index.js +0 -16
  47. package/logger.js +0 -99
  48. package/router/ClientRouter.js +0 -19
  49. package/router/ServerRouter.js +0 -19
  50. package/router/index.js +0 -32
  51. package/router.js +0 -16
  52. package/scripts/build.js +0 -42
  53. package/scripts/checkVersion.js +0 -5
  54. package/scripts/devBuild.js +0 -42
  55. package/scripts/devServe.js +0 -43
  56. package/scripts/loadEnvironmentVariables.js +0 -24
  57. package/scripts/loadScriptsBeforeServerStarts.js +0 -47
  58. package/scripts/prepare.js +0 -19
  59. package/scripts/registerAliases.js +0 -30
  60. package/scripts/serve.js +0 -43
  61. package/scripts/start.js +0 -35
  62. package/scripts/validator.js +0 -127
  63. package/server/expressServer.js +0 -50
  64. package/server/mainIndex.js +0 -65
  65. package/server/mainServer.js +0 -70
  66. package/server/renderer/document/Body.js +0 -36
  67. package/server/renderer/document/Head.js +0 -43
  68. package/server/renderer/document/index.js +0 -27
  69. package/server/renderer/extract.js +0 -87
  70. package/server/renderer/handler.js +0 -240
  71. package/server/renderer/index.js +0 -12
  72. package/server/renderer/render.js +0 -84
  73. package/server/renderer/userAgentUtil.js +0 -55
  74. package/server/startServer.js +0 -66
  75. package/server/utils/metaTags.js +0 -13
  76. package/server/utils/userAgentUtil.js +0 -51
  77. package/server/utils/validator.js +0 -127
  78. package/tsconfig.json +0 -110
  79. package/webpack/babel-plugins/remove-client.plugin.js +0 -31
  80. package/webpack/babel-plugins/remove-ssr.plugin.js +0 -21
  81. package/webpack/babel.config.client.js +0 -24
  82. package/webpack/babel.config.js +0 -20
  83. package/webpack/babel.config.ssr.js +0 -24
  84. package/webpack/base.babel.js +0 -175
  85. package/webpack/development.client.babel.js +0 -85
  86. package/webpack/plugins/mime-types.js +0 -82
  87. package/webpack/plugins/route-manifest-copy.js +0 -122
  88. package/webpack/plugins/route-manifest-plugin.js +0 -122
  89. package/webpack/plugins/upload-assets-plugin.js +0 -181
  90. package/webpack/production.client.babel.js +0 -78
  91. package/webpack/production.ssr.babel.js +0 -61
  92. package/webpack/scssParams.js +0 -51
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- spawnSync
5
- } = require("child_process");
6
- const path = require("path");
7
- const {
8
- name
9
- } = require(`${process.env.PWD}/package.json`);
10
- const {
11
- BUILD_OUTPUT_PATH
12
- } = require(`${process.env.PWD}/config/config.json`);
13
- function arrayToObject(array) {
14
- const obj = {};
15
- array.forEach(item => {
16
- const [key, value] = item.split("=");
17
- if (value) obj[key] = value;
18
- });
19
- return obj;
20
- }
21
-
22
- /**
23
- * @description - Serves production build of the application.
24
- */
25
-
26
- function start() {
27
- const commandLineArguments = process.argv.slice(2);
28
- const argumentsObject = arrayToObject(commandLineArguments);
29
- const dirname = path.resolve(__dirname, "../");
30
- spawnSync("npm", ["run", "serve", `--src_path=${process.env.PWD}`, `--app_name=${name || "catalyst_app"}`], {
31
- cwd: dirname,
32
- stdio: "inherit",
33
- env: {
34
- ...process.env,
35
- src_path: process.env.PWD,
36
- build_output_path: BUILD_OUTPUT_PATH,
37
- NODE_ENV: "production",
38
- IS_DEV_COMMAND: true,
39
- ...argumentsObject
40
- }
41
- });
42
- }
43
- start();
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- const appConfig = require(`${process.env.src_path}/config/config.json`);
8
- const {
9
- validateConfigFile
10
- } = require("./validator.js");
11
-
12
- /**
13
- * @description stores all config.json key value into process.env before server starts.
14
- */
15
- const loadEnvironmentVariables = () => {
16
- if (validateConfigFile(appConfig)) {
17
- for (let k in appConfig) {
18
- // below code provides support for object handling present in config.
19
- // However, for usage on client the client logic in define plugin needs to be checked and updated
20
- process.env[k] = typeof appConfig[k] === "object" ? JSON.stringify(appConfig[k]) : appConfig[k];
21
- }
22
- }
23
- };
24
- var _default = exports.default = loadEnvironmentVariables;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- var _cssModulesRequireHook = _interopRequireDefault(require("@dr.pogodin/css-modules-require-hook"));
4
- var _path = _interopRequireDefault(require("path"));
5
- var _moduleAlias = _interopRequireDefault(require("module-alias"));
6
- var _loadEnvironmentVariables = _interopRequireDefault(require("./loadEnvironmentVariables"));
7
- var _logger = require("../logger.js");
8
- var _validator = require("./validator.js");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const {
11
- cssModulesIdentifierDev
12
- } = require(`${__dirname}/../config.json`);
13
- const {
14
- _moduleAliases
15
- } = require(`${process.env.src_path}/package.json`);
16
- // stores your config keys in enviorments variables
17
- (0, _loadEnvironmentVariables.default)();
18
-
19
- // creates logger instance with provided config and stores them at global level.
20
- (0, _logger.configureLogger)({
21
- enableDebugLogs: process.env.ENABLE_DEBUG_LOGS,
22
- enableFileLogging: process.env.ENABLE_FILE_LOGGING,
23
- enableConsoleLogging: process.env.ENABLE_CONSOLE_LOGGING
24
- });
25
-
26
- // resolves module alias imports
27
- if ((0, _validator.validateModuleAlias)(_moduleAliases)) {
28
- _moduleAlias.default.addAliases(Object.keys(_moduleAliases || []).reduce((resultMap, aliasName) => {
29
- const aliasPath = _moduleAliases[aliasName];
30
- if (aliasPath.includes("server")) {
31
- if (process.env.NODE_ENV !== "production") {
32
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
33
- } else {
34
- resultMap[aliasName] = _path.default.join(process.env.src_path, process.env.BUILD_OUTPUT_PATH);
35
- }
36
- } else resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
37
- return resultMap;
38
- }, {}));
39
- }
40
-
41
- // compile css-variables in realtime in dev mode.
42
- if (process.env.NODE_ENV === "development") (0, _cssModulesRequireHook.default)({
43
- extensions: [".scss", ".css"],
44
- generateScopedName: cssModulesIdentifierDev,
45
- devMode: true,
46
- ignore: _path.default.join(process.env.src_path, "/src/static/css/base/(?!.*.scss$).*")
47
- });
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- spawnSync
5
- } = require("child_process");
6
- const path = require("path");
7
-
8
- /**
9
- * @description - it creates build and generate types requried for function definations.
10
- */
11
- function prepare() {
12
- console.log("Running prepare....");
13
- const dirname = path.resolve(__dirname, "../");
14
- spawnSync("npm", ["run", "prepare"], {
15
- cwd: dirname,
16
- stdio: 'inherit'
17
- });
18
- }
19
- prepare();
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var _path = _interopRequireDefault(require("path"));
4
- var _moduleAlias = _interopRequireDefault(require("module-alias"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
- const pjp = process.env.src_path + `/package.json`;
7
- const cfg = `${process.env.src_path}/config/config`;
8
- // const config = require(cfg)
9
- // const { _moduleAliases } = require(pjp)
10
- const config = require(`${process.env.src_path}/config/config`);
11
- const {
12
- _moduleAliases
13
- } = require(`${process.env.src_path}/package.json`);
14
-
15
- // Add module aliases, but for server aliases (prefix by the `$` symbol), change
16
- // the directory to match the current build directory (e.g. /dist)
17
- // This ensures that all alises are properly referencing the babel-built
18
- // server files
19
- _moduleAlias.default.addAliases(Object.keys(_moduleAliases || []).reduce((resultMap, aliasName) => {
20
- const aliasPath = _moduleAliases[aliasName];
21
- const sym = aliasName[0];
22
- if (sym === "$") {
23
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath.split("/").slice(1).join("/"));
24
- } else if (aliasPath.includes("templates")) {
25
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
26
- } else {
27
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
28
- }
29
- return resultMap;
30
- }, {}));
package/scripts/serve.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- spawnSync
5
- } = require("child_process");
6
- const path = require("path");
7
- const {
8
- name
9
- } = require(`${process.env.PWD}/package.json`);
10
- const {
11
- BUILD_OUTPUT_PATH
12
- } = require(`${process.env.PWD}/config/config.json`);
13
- function arrayToObject(array) {
14
- const obj = {};
15
- array.forEach(item => {
16
- const [key, value] = item.split("=");
17
- if (value) obj[key] = value;
18
- });
19
- return obj;
20
- }
21
-
22
- /**
23
- * @description - Serves production build of the application.
24
- */
25
-
26
- function start() {
27
- const commandLineArguments = process.argv.slice(2);
28
- const argumentsObject = arrayToObject(commandLineArguments);
29
- const dirname = path.resolve(__dirname, "../");
30
- spawnSync("npm", ["run", "serve", `--src_path=${process.env.PWD}`, `--app_name=${name || "catalyst_app"}`], {
31
- cwd: dirname,
32
- stdio: "inherit",
33
- env: {
34
- ...process.env,
35
- src_path: process.env.PWD,
36
- build_output_path: BUILD_OUTPUT_PATH,
37
- NODE_ENV: "production",
38
- IS_DEV_COMMAND: false,
39
- ...argumentsObject
40
- }
41
- });
42
- }
43
- start();
package/scripts/start.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- spawnSync
5
- } = require("child_process");
6
- const path = require("path");
7
- function arrayToObject(array) {
8
- const obj = {};
9
- array.forEach(item => {
10
- const [key, value] = item.split("=");
11
- if (value) obj[key] = value;
12
- });
13
- return obj;
14
- }
15
-
16
- /**
17
- * @description - starts webpack dev server and node server.
18
- */
19
- function start() {
20
- const commandLineArguments = process.argv.slice(2);
21
- const argumentsObject = arrayToObject(commandLineArguments);
22
- const dirname = path.resolve(__dirname, "../");
23
- spawnSync("npm", ["run", "start", `--src_path=${process.env.PWD}`], {
24
- cwd: dirname,
25
- stdio: "inherit",
26
- env: {
27
- ...process.env,
28
- src_path: process.env.PWD,
29
- NODE_ENV: "development",
30
- IS_DEV_COMMAND: false,
31
- ...argumentsObject
32
- }
33
- });
34
- }
35
- start();
@@ -1,127 +0,0 @@
1
- "use strict";
2
-
3
- const pc = require("picocolors");
4
- const handleError = e => {
5
- console.log(pc.red("Failed to start server: "), e);
6
- };
7
- const validatePreInitServer = fn => {
8
- try {
9
- if (!fn) throw new Error("preServerInit named function should be defined in server/index.js");
10
- if (typeof fn !== "function") throw new Error("preServerInit should be function present in server/index.js");
11
- return true;
12
- } catch (e) {
13
- handleError(e);
14
- }
15
- };
16
- const validateMiddleware = fn => {
17
- try {
18
- if (!fn) throw new Error("addMiddlewares named function not found in server/server.js");
19
- if (typeof fn !== "function") throw new Error("addMiddlewares should be function present in server/server.js");
20
- return true;
21
- } catch (e) {
22
- handleError(e);
23
- }
24
- };
25
- const validateReducerFunction = fn => {
26
- try {
27
- if (!fn) throw new Error("reducer not found in src/js/containers/App/reducer");
28
- if (typeof fn !== "function") throw new Error("reducer should present in src/js/containers/App/reducer");
29
- return true;
30
- } catch (e) {
31
- handleError(e);
32
- }
33
- };
34
- const validateConfigFile = obj => {
35
- try {
36
- if (!obj) throw new Error("config not found in config folder");
37
- if (typeof obj !== "object") throw new Error("config object should be exported from config folder inside your project root directory");
38
- if (typeof obj === "object") {
39
- const requiredConfigKeys = {
40
- NODE_SERVER_HOSTNAME: "",
41
- NODE_SERVER_PORT: "",
42
- WEBPACK_DEV_SERVER_HOSTNAME: "",
43
- WEBPACK_DEV_SERVER_PORT: "",
44
- BUILD_OUTPUT_PATH: "",
45
- PUBLIC_STATIC_ASSET_PATH: "",
46
- PUBLIC_STATIC_ASSET_URL: "",
47
- CLIENT_ENV_VARIABLES: [],
48
- ANALYZE_BUNDLE: ""
49
- };
50
- for (let key in requiredConfigKeys) {
51
- if (!(key in obj)) throw new Error(`${key} key not found inside config.json`);
52
- }
53
- }
54
- return true;
55
- } catch (e) {
56
- handleError(e);
57
- }
58
- };
59
- const validatePackageJson = obj => {
60
- try {
61
- if (!obj) throw new Error("package.json not found in the project");
62
- if (typeof obj !== "object") throw new Error("package.json should be defined in project root directory");
63
- return true;
64
- } catch (e) {
65
- handleError(e);
66
- }
67
- };
68
- const validateModuleAlias = obj => {
69
- try {
70
- if (!obj) throw new Error("moduleAliases not found in package.json file present in root directory.");
71
- if (typeof obj !== "object") throw new Error("moduleAliases named object should be exported from package.json");
72
- if (typeof obj === "object") {
73
- const requiredModuleAliases = {
74
- "@api": "api.js",
75
- "@containers": "src/js/containers",
76
- "@server": "server",
77
- "@config": "config",
78
- "@css": "src/static/css",
79
- "@routes": "src/js/routes/"
80
- };
81
- for (let key in requiredModuleAliases) {
82
- if (!(key in obj)) throw new Error(`${key} module alias not defined inside package.json`);
83
- }
84
- }
85
- return true;
86
- } catch (e) {
87
- handleError(e);
88
- }
89
- };
90
- const validateConfigureStore = fn => {
91
- try {
92
- if (!fn) throw new Error("configureStore not found in file src/js/store/index.js");
93
- if (typeof fn !== "function") throw new Error("configureStore should be function exported from src/js/store/index.js");
94
- return true;
95
- } catch (e) {
96
- handleError(e);
97
- }
98
- };
99
- const validateGetRoutes = fn => {
100
- try {
101
- if (!fn) throw new Error("getRoutes not found in file src/js/routes/utils.js");
102
- if (typeof fn !== "function") throw new Error("getRoutes should be function exported from src/js/routers/index.js");
103
- return true;
104
- } catch (e) {
105
- handleError(e);
106
- }
107
- };
108
- const validateCustomDocument = fn => {
109
- try {
110
- if (!fn) throw new Error("document not found in file server/document.js");
111
- if (typeof fn !== "function") throw new Error("document should be a react component exported from server/document.js");
112
- return true;
113
- } catch (e) {
114
- handleError(e);
115
- }
116
- };
117
- module.exports = {
118
- validateConfigFile,
119
- validateConfigureStore,
120
- validateCustomDocument,
121
- validateGetRoutes,
122
- validatePackageJson,
123
- validateReducerFunction,
124
- validateModuleAlias,
125
- validatePreInitServer,
126
- validateMiddleware
127
- };
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
- var _express = _interopRequireDefault(require("express"));
9
- var _bodyParser = _interopRequireDefault(require("body-parser"));
10
- var _compression = _interopRequireDefault(require("compression"));
11
- var _cookieParser = _interopRequireDefault(require("cookie-parser"));
12
- var _expressStaticGzip = _interopRequireDefault(require("express-static-gzip"));
13
- var _renderer = _interopRequireDefault(require("./renderer"));
14
- var _server = require("@server/server.js");
15
- var _validator = require("./utils/validator");
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
- const env = process.env.NODE_ENV || "development";
18
- const app = (0, _express.default)();
19
-
20
- // This middleware is being used to extract the body of the request
21
- app.use(_bodyParser.default.json());
22
-
23
- // This middleware has been added to accommodate “byetstream array”
24
- app.use(_bodyParser.default.raw({
25
- type: "application/*"
26
- }));
27
-
28
- // This middleware is being used to parse cookies!
29
- app.use((0, _cookieParser.default)());
30
-
31
- // All the middlewares defined by the user will run here.
32
- if ((0, _validator.validateMiddleware)(_server.addMiddlewares)) (0, _server.addMiddlewares)(app);
33
-
34
- // The middleware will attempt to compress response bodies for all request that traverse through the middleware
35
- app.use((0, _compression.default)());
36
-
37
- // This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
38
- // expressStaticGzip will compress the assets.
39
- if (env === "production") {
40
- app.use(process.env.PUBLIC_STATIC_ASSET_PATH, (0, _expressStaticGzip.default)(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`), {
41
- enableBrotli: true,
42
- orderPreference: ["br", "gzip", "deflate"]
43
- }));
44
- } else {
45
- app.use(process.env.PUBLIC_STATIC_ASSET_PATH, _express.default.static(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`)));
46
- }
47
-
48
- // This middleware handles document requests.
49
- app.use("*", _renderer.default);
50
- var _default = exports.default = app;
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- var _index = require("$server/index.js");
4
- var _mainServer = require("./mainServer.js");
5
- var _mainServer2 = _interopRequireDefault(_mainServer);
6
- var _validator = require("./utils/validator.js");
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
- // import("../scripts/registerAliases.js")
9
- const env = process.env.NODE_ENV || "development";
10
- // function defined on user which needs to be run before server starts
11
- if ((0, _validator.validatePreInitServer)(_index.preServerInit)) (0, _index.preServerInit)();
12
- process.on("uncaughtException", (err, origin) => {
13
- console.log(">>>>", process.stderr.fd);
14
- console.log(`Caught exception: ${err}\n` + `Exception origin: ${origin}`);
15
- });
16
- process.on("SIGINT", function (data) {
17
- console.log("SIGINT");
18
- console.log(data);
19
- process.exit(0);
20
- });
21
- process.on("uncaughtExceptionMonitor", (err, origin) => {
22
- console.log(">>>>>", err, origin);
23
- });
24
- process.on("message", function (msg) {
25
- if (msg == "shutdown") {
26
- console.log("Closing all connections...");
27
- setTimeout(function () {
28
- console.log("Finished closing connections");
29
- process.exit(0);
30
- }, 1500);
31
- }
32
- });
33
- process.loadableConfig = {
34
- CLIENT_ONLY_RENDER: process.env["CLIENT_ONLY_RENDER"] === "true",
35
- SERVER_SIDE_RENDER: process.env["SERVER_SIDE_RENDER"] === "true"
36
- };
37
- if (env === "development") {
38
- // In development, we compile css-modules on the fly on the server. This is
39
- // not necessary in production since we build renderer and server files with
40
- // webpack and babel.
41
- // import("css-modules-require-hook").then((methods) => {
42
- // console.log(">>>>css-modules")
43
- // methods.default({
44
- // extensions: [".scss"],
45
- // generateScopedName: "[name]__[local]",
46
- // devMode: true,
47
- // })
48
- // })
49
- // Add better stack tracing for promises in dev mode
50
- process.on("unhandledRejection", r => console.debug(r));
51
- }
52
- const port = process.env.PORT || process.env.APPLICATION_PORT || 3000;
53
- const host = env === "development" ? "localhost" : process.env.DEV_SERVER_HOSTNAME;
54
- // import("./server.js").then((server) => {
55
- _mainServer2.default.listen(port, error => {
56
- if (error) {
57
- console.log("Server Starting Error");
58
- } else {
59
- console.log(`Application server mounted on http://${host}:${port}.`);
60
- }
61
- });
62
-
63
- // })
64
-
65
- /* eslint-enable */
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _path = require("path");
7
- var _path2 = _interopRequireDefault(_path);
8
- var _express = require("express");
9
- var _express2 = _interopRequireDefault(_express);
10
- var _bodyParser = require("body-parser");
11
- var _bodyParser2 = _interopRequireDefault(_bodyParser);
12
- var _compression = require("compression");
13
- var _compression2 = _interopRequireDefault(_compression);
14
- var _cookieParser = require("cookie-parser");
15
- var _cookieParser2 = _interopRequireDefault(_cookieParser);
16
- var _expressStaticGzip = require("express-static-gzip");
17
- var _expressStaticGzip2 = _interopRequireDefault(_expressStaticGzip);
18
- var _renderer = require("./renderer");
19
- var _renderer2 = _interopRequireDefault(_renderer);
20
- var _server = require("$server/server.js");
21
- var _validator = require("./utils/validator");
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
- const env = process.env.NODE_ENV || "development";
24
- const app = (0, _express2.default)();
25
-
26
- //Use-case: We are using body-parser here for widget-factory,
27
- //we need to extract the body of request which Native will hit at our end.
28
- app.use(_bodyParser2.default.json());
29
-
30
- // This change is added to accommodate “byetstream array”
31
- // which is octet-stream format coming from android!
32
- app.use(_bodyParser2.default.raw({
33
- type: "application/*"
34
- }));
35
-
36
- // parse cookies!
37
- app.use((0, _cookieParser2.default)());
38
-
39
- // Apply custom midlewares
40
- if ((0, _validator.validateMiddleware)(_server.addMiddlewares)) (0, _server.addMiddlewares)(app);
41
-
42
- // gzip
43
- app.use((0, _compression2.default)());
44
-
45
- // We upload the assets on our s3 bucket and serve them through our CDN.
46
- // However if our CDN is down all we have to do is change the PUBLIC_ASSET_PATH in basecamp
47
- // to "node_server_ip/assets" (Example: http://13.127.237.229:8443/assets) to serve the assets from our node server.
48
- // When we make production builds on our local system we change the PUBLIC_ASSET_PATH to "http://localhost:3005/assets/".
49
- // In this case all the asset requests are made to the node server running on our local system and are served locally.
50
- if (env === "production") {
51
- app.use("/assets", (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../" + process.env.PUBLIC_OUTPUT_PATH), {
52
- enableBrotli: true,
53
- orderPreference: ["br", "gzip", "deflate"]
54
- }), (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../src/static/images"), {
55
- enableBrotli: true,
56
- orderPreference: ["br", "gzip", "deflate"]
57
- }), (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../src/static/fonts"), {
58
- enableBrotli: true,
59
- orderPreference: ["br", "gzip", "deflate"]
60
- }), (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../src/js/lib"), {
61
- enableBrotli: true,
62
- orderPreference: ["br", "gzip", "deflate"]
63
- }));
64
- } else {
65
- app.use("/assets", _express2.default.static(_path2.default.join(__dirname, "../" + process.env.PUBLIC_OUTPUT_PATH)), _express2.default.static(_path2.default.join(__dirname, `../${process.env.APPLICATION}/src/static/images`)), _express2.default.static(_path2.default.join(__dirname, `../${process.env.APPLICATION}/src/static/fonts`)), _express2.default.static(_path2.default.join(__dirname, `../${process.env.APPLICATION}/src/js/lib`)));
66
- }
67
-
68
- // handles document request
69
- app.use("*", _renderer2.default);
70
- exports.default = app;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Body = Body;
7
- var _react = _interopRequireDefault(require("react"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * Body component which will be used in page component
11
- * @param {object} initialState - initial state object for redux store
12
- * @param {object} firstFoldCss - style elements extracted for initial page load
13
- * @param {object} firstFoldJS - javascript elements extracted for initial page load
14
- * @param {object} jsx - page jsx code
15
- * @param {object} statusCode - document request status code
16
- * @param {object} fetcherData - contains data from executing serverFetcher function
17
- */
18
- function Body(props) {
19
- const {
20
- initialState = {},
21
- statusCode = "",
22
- firstFoldCss = "",
23
- firstFoldJS = "",
24
- jsx = "",
25
- fetcherData = {}
26
- } = props;
27
- return /*#__PURE__*/_react.default.createElement("body", null, firstFoldCss, firstFoldJS, jsx, /*#__PURE__*/_react.default.createElement("script", {
28
- dangerouslySetInnerHTML: {
29
- __html: `
30
- window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
31
- window.__STATUS_CODE__ = ${statusCode}
32
- window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
33
- `
34
- }
35
- }), props.children);
36
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Head = Head;
7
- var _react = _interopRequireDefault(require("react"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * Head component which will be used in page rendering
11
- * @param {string} pageCss - includes all styles for page css
12
- * @param {object} pageJS - async scripts for loading chunks
13
- * @param {function} metaTagFunction - user defined function which returns meta tags in array
14
- * @param {boolean} isBot - checks if request is made by bot
15
- * @param {string} publicAssetPath - public asset path for assets
16
- * @param {object} fetcherData - router fetched data
17
- */
18
- function Head(props) {
19
- const {
20
- pageCss,
21
- pageJS,
22
- metaTags,
23
- isBot,
24
- publicAssetPath,
25
- fetcherData
26
- } = props;
27
- return /*#__PURE__*/_react.default.createElement("head", null, /*#__PURE__*/_react.default.createElement("meta", {
28
- charSet: "utf-8"
29
- }), /*#__PURE__*/_react.default.createElement("meta", {
30
- name: "viewport",
31
- content: "width=device-width, initial-scale=1"
32
- }), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
33
- rel: "preconnect",
34
- href: publicAssetPath
35
- }), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
36
- rel: "dns-prefetch",
37
- href: publicAssetPath
38
- }), metaTags && metaTags, !isBot && pageJS, !isBot && /*#__PURE__*/_react.default.createElement("style", {
39
- dangerouslySetInnerHTML: {
40
- __html: pageCss
41
- }
42
- }), props.children);
43
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Head = require("./Head");
7
- Object.keys(_Head).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Head[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _Head[key];
14
- }
15
- });
16
- });
17
- var _Body = require("./Body");
18
- Object.keys(_Body).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _Body[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _Body[key];
25
- }
26
- });
27
- });