@zengenti/contensis-react-base 3.0.1-beta.13 → 3.0.1-beta.14

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.
@@ -14,6 +14,7 @@ import { Op, Query } from 'contensis-core-api';
14
14
  import { s as setCachingHeaders, u as url } from './urls-eac9a747.js';
15
15
  import 'isomorphic-fetch';
16
16
  import express from 'express';
17
+ import { Server } from 'http';
17
18
  import httpProxy from 'http-proxy';
18
19
  import fs from 'fs';
19
20
  import path from 'path';
@@ -32,6 +33,7 @@ import { CookiesProvider } from 'react-cookie';
32
33
  import { c as createStore, s as setVersionStatus, a as setVersion } from './version-e3a5ec66.js';
33
34
  import { s as setCurrentProject } from './actions-180948dd.js';
34
35
  import { s as selectSurrogateKeys, a as selectRouteEntry, b as selectCurrentProject, g as getImmutableOrJS } from './selectors-a5e5835b.js';
36
+ import chalk from 'chalk';
35
37
  import 'history';
36
38
  import '@redux-saga/core/effects';
37
39
  import 'loglevel';
@@ -665,27 +667,6 @@ const makeLinkDepthMiddleware = ({
665
667
  const servers$1 = SERVERS;
666
668
  /* global SERVERS */
667
669
 
668
- const projects = PROJECTS;
669
- /* global PROJECTS */
670
-
671
- const DisplayStartupConfiguration = config => {
672
- /* eslint-disable no-console */
673
- console.log();
674
- console.log(`Configured servers:
675
- `, JSON.stringify(servers$1, null, 2));
676
- console.log();
677
- console.log(`Configured projects:
678
- `, JSON.stringify(projects, null, 2));
679
- console.log();
680
- console.log('Reverse proxy paths: ', JSON.stringify(config.reverseProxyPaths, null, 2));
681
- console.log();
682
- if (config.staticFolderPath) console.log(`Serving static assets from: "/dist/${config.staticFolderPath}/"`);
683
- /* eslint-enable no-console */
684
- };
685
-
686
- const servers = SERVERS;
687
- /* global SERVERS */
688
-
689
670
  const project = PROJECT;
690
671
  /* global PROJECT */
691
672
 
@@ -699,7 +680,7 @@ const deliveryProxy = httpProxy.createProxyServer();
699
680
  const reverseProxies = (app, reverseProxyPaths = []) => {
700
681
  deliveryApiProxy(deliveryProxy, app);
701
682
  app.all(reverseProxyPaths, (req, res) => {
702
- const target = req.hostname.indexOf('preview-') || req.hostname.indexOf('preview.') || req.hostname === 'localhost' ? servers.previewIis || servers.iis : servers.iis;
683
+ const target = req.hostname.indexOf('preview-') || req.hostname.indexOf('preview.') || req.hostname === 'localhost' ? servers$1.previewIis || servers$1.iis : servers$1.iis;
703
684
  assetProxy.web(req, res, {
704
685
  target,
705
686
  changeOrigin: true
@@ -716,7 +697,7 @@ const deliveryApiProxy = (apiProxy, app) => {
716
697
  // This is just here to stop cors requests on localhost. In Production this is mapped using varnish.
717
698
  app.all(['/api/delivery/*', '/api/image/*'], (req, res) => {
718
699
  /* eslint-disable no-console */
719
- console.log(`Proxying api request to ${servers.alias}`);
700
+ console.log(`Proxying api request to ${servers$1.alias}`);
720
701
  apiProxy.web(req, res, {
721
702
  target: deliveryApiHostname,
722
703
  changeOrigin: true
@@ -841,6 +822,27 @@ const staticAssets = (app, {
841
822
  }));
842
823
  };
843
824
 
825
+ const servers = SERVERS;
826
+ /* global SERVERS */
827
+
828
+ const projects = PROJECTS;
829
+ /* global PROJECTS */
830
+
831
+ const DisplayStartupConfiguration = config => {
832
+ /* eslint-disable no-console */
833
+ console.log();
834
+ console.log(`Configured servers:
835
+ `, JSON.stringify(servers, null, 2));
836
+ console.log();
837
+ console.log(`Configured projects:
838
+ `, JSON.stringify(projects, null, 2));
839
+ console.log();
840
+ console.log('Reverse proxy paths: ', JSON.stringify(config.reverseProxyPaths, null, 2));
841
+ console.log();
842
+ if (config.staticFolderPath) console.log(`Serving static assets from: "/dist/${config.staticFolderPath}/"`);
843
+ /* eslint-enable no-console */
844
+ };
845
+
844
846
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
845
847
 
846
848
  /**
@@ -4149,6 +4151,25 @@ const getVersionInfo = staticFolderPath => {
4149
4151
  }
4150
4152
  };
4151
4153
 
4154
+ /* eslint-disable no-console */
4155
+ const unhandledExceptionHandler = (handleExceptions = true) => {
4156
+ const exceptionTypes = handleExceptions === true ? ['uncaughtException', 'unhandledRejection', 'SIGTERM', 'SIGINT'] // Default exception types to add event listeners for
4157
+ : Array.isArray(handleExceptions) // In future we could accept an array of specific exception types to handle for a specific application?
4158
+ ? handleExceptions : [];
4159
+
4160
+ for (const type of exceptionTypes) {
4161
+ process.on(type, err => {
4162
+ if (err && err instanceof Error) {
4163
+ // Print a message to inform admins and developers the error should not be ignored
4164
+ console.log(`${`[contensis-react-base] ❌ ${chalk.red.bold(`${type} - ${err.message}`)}`}`);
4165
+ console.log(chalk.gray` - you are seeing this because we have tried to prevent the app from completely crashing - you should not ignore this problem`); // Log the error to server console
4166
+
4167
+ console.error(err);
4168
+ }
4169
+ });
4170
+ }
4171
+ };
4172
+
4152
4173
  const webApp = (app, ReactApp, config) => {
4153
4174
  const {
4154
4175
  stateType = 'immutable',
@@ -4163,13 +4184,16 @@ const webApp = (app, ReactApp, config) => {
4163
4184
  allowedGroups,
4164
4185
  globalGroups,
4165
4186
  disableSsrRedux,
4166
- handleResponses
4187
+ handleResponses,
4188
+ handleExceptions = true
4167
4189
  } = config;
4168
4190
  const staticRoutePath = config.staticRoutePath || staticFolderPath;
4169
4191
  const bundleData = getBundleData(config, staticRoutePath);
4170
4192
  const attributes = stringifyAttributes(scripts.attributes);
4171
4193
  scripts.startup = scripts.startup || startupScriptFilename;
4172
4194
  const responseHandler = typeof handleResponses === 'function' ? handleResponses : handleResponse;
4195
+ if (handleExceptions !== false) unhandledExceptionHandler(); // Create `process.on` event handlers for unhandled exceptions (Node v15+)
4196
+
4173
4197
  const versionInfo = getVersionInfo(staticFolderPath);
4174
4198
  app.get('/*', async (request, response) => {
4175
4199
  const {
@@ -4362,6 +4386,7 @@ const webApp = (app, ReactApp, config) => {
4362
4386
  };
4363
4387
 
4364
4388
  const app = express();
4389
+ let server = new Server(); // new Server() is just a stub to assert the type for the export
4365
4390
 
4366
4391
  const start = (ReactApp, config, ServerFeatures) => {
4367
4392
  global.PACKAGE_JSON = config.packagejson;
@@ -4378,7 +4403,7 @@ const start = (ReactApp, config, ServerFeatures) => {
4378
4403
  staticAssets(app, config);
4379
4404
  webApp(app, ReactApp, config);
4380
4405
  app.on('ready', async () => {
4381
- const server = app.listen(3001, () => {
4406
+ server = app.listen(3001, () => {
4382
4407
  console.info(`HTTP server is listening @ port 3001`);
4383
4408
  setTimeout(function () {
4384
4409
  app.emit('app_started');
@@ -4395,6 +4420,7 @@ const start = (ReactApp, config, ServerFeatures) => {
4395
4420
  var internalServer = {
4396
4421
  app,
4397
4422
  apiProxy: deliveryProxy,
4423
+ server,
4398
4424
  start
4399
4425
  };
4400
4426