@dr.pogodin/react-utils 1.40.8 → 1.40.9
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/build/development/index.js.map +1 -1
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +2 -1
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +0 -7
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +2 -2
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +0 -7
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/index.d.ts +3 -2
- package/build/types-code/server/index.d.ts +4 -5
- package/build/types-code/server/renderer.d.ts +13 -4
- package/build/types-code/server/server.d.ts +3 -4
- package/build/types-code/server/utils/errors.d.ts +1 -8
- package/package.json +34 -34
- package/src/index.ts +10 -2
- package/src/server/index.ts +9 -1
- package/src/server/renderer.tsx +6 -6
- package/src/server/server.ts +3 -3
- package/src/server/utils/errors.ts +4 -8
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import 'styles/global.scss';
|
|
2
|
-
import type
|
|
3
|
-
declare const server: (typeof
|
|
2
|
+
import type ServerFactoryT from './server';
|
|
3
|
+
declare const server: (typeof ServerFactoryT) | null;
|
|
4
4
|
declare const client: any;
|
|
5
5
|
export { type AsyncCollectionT, type AsyncCollectionLoaderT, type AsyncDataEnvelopeT, type AsyncDataLoaderT, type ForceT, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateResT, type ValueOrInitializerT, getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType, } from '@dr.pogodin/react-global-state';
|
|
6
6
|
export * from './shared/components';
|
|
7
|
+
export { type BeforeRenderResT, type BeforeRenderT, type ConfigT, type ServerSsrContext, type ServerT, } from './server';
|
|
7
8
|
export { type Listener, type Theme, config, Barrier, Emitter, isomorphy, getSsrContext, Semaphore, splitComponent, themed, ThemeProvider, time, webpack, withRetries, } from './shared/utils';
|
|
8
9
|
export { client, server };
|
|
@@ -2,9 +2,10 @@ import 'source-map-support/register';
|
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import 'raf/polyfill';
|
|
4
4
|
import { type Configuration } from 'webpack';
|
|
5
|
-
import { type OptionsT as ServerOptionsT, getDefaultCspSettings } from './server';
|
|
5
|
+
import { type OptionsT as ServerOptionsT, type ServerT, getDefaultCspSettings } from './server';
|
|
6
6
|
import { errors } from './utils';
|
|
7
|
-
export {
|
|
7
|
+
export { type BeforeRenderResT, type BeforeRenderT, type ConfigT, type ServerSsrContext, } from './renderer';
|
|
8
|
+
export { errors, getDefaultCspSettings, type ServerT };
|
|
8
9
|
type OptionsT = ServerOptionsT & {
|
|
9
10
|
https?: {
|
|
10
11
|
cert: string;
|
|
@@ -132,9 +133,7 @@ type OptionsT = ServerOptionsT & {
|
|
|
132
133
|
* an object with created Express and HTTP servers.
|
|
133
134
|
*/
|
|
134
135
|
declare function launchServer(webpackConfig: Configuration, options: OptionsT): Promise<{
|
|
135
|
-
expressServer:
|
|
136
|
-
logger: import("./renderer").LoggerI;
|
|
137
|
-
};
|
|
136
|
+
expressServer: ServerT;
|
|
138
137
|
httpServer: http.Server;
|
|
139
138
|
}>;
|
|
140
139
|
declare namespace launchServer {
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
import { type Request, type RequestHandler } from 'express';
|
|
5
5
|
import { type ComponentType } from 'react';
|
|
6
6
|
import winston from 'winston';
|
|
7
|
+
import { SsrContext } from '@dr.pogodin/react-global-state';
|
|
7
8
|
import { type BuildInfoT } from '../shared/utils/isomorphy/buildInfo';
|
|
9
|
+
import { type ChunkGroupsT, type SsrContextT } from '../shared/utils/globalState';
|
|
8
10
|
import { type Configuration } from 'webpack';
|
|
9
11
|
interface LogMethodI {
|
|
10
12
|
(level: string, message: string, ...meta: any[]): void;
|
|
@@ -24,6 +26,13 @@ export declare enum SCRIPT_LOCATIONS {
|
|
|
24
26
|
DEFAULT = "DEFAULT",
|
|
25
27
|
HEAD_OPEN = "HEAD_OPEN"
|
|
26
28
|
}
|
|
29
|
+
export declare class ServerSsrContext<StateT> extends SsrContext<StateT> implements SsrContextT<StateT> {
|
|
30
|
+
chunkGroups: ChunkGroupsT;
|
|
31
|
+
chunks: string[];
|
|
32
|
+
req: Request;
|
|
33
|
+
status: number;
|
|
34
|
+
constructor(req: Request, chunkGroups: ChunkGroupsT, initialState?: StateT);
|
|
35
|
+
}
|
|
27
36
|
type ScriptT = {
|
|
28
37
|
code: string;
|
|
29
38
|
location: SCRIPT_LOCATIONS;
|
|
@@ -45,15 +54,15 @@ export declare function isBrotliAcceptable(req: Request): boolean;
|
|
|
45
54
|
export declare function newDefaultLogger({ defaultLogLevel, }?: {
|
|
46
55
|
defaultLogLevel?: string | undefined;
|
|
47
56
|
}): winston.Logger;
|
|
48
|
-
type ConfigT = {
|
|
57
|
+
export type ConfigT = {
|
|
49
58
|
[key: string]: ConfigT | string;
|
|
50
59
|
};
|
|
51
|
-
type BeforeRenderResT = {
|
|
60
|
+
export type BeforeRenderResT = {
|
|
52
61
|
configToInject?: ConfigT;
|
|
53
62
|
extraScripts?: Array<ScriptT | string>;
|
|
54
63
|
initialState?: any;
|
|
55
64
|
};
|
|
56
|
-
type BeforeRenderT = (req: Request, config: ConfigT) => BeforeRenderResT | Promise<BeforeRenderResT>;
|
|
65
|
+
export type BeforeRenderT = (req: Request, config: ConfigT) => BeforeRenderResT | Promise<BeforeRenderResT>;
|
|
57
66
|
type CacheRefT = {
|
|
58
67
|
key: string;
|
|
59
68
|
maxage?: number;
|
|
@@ -69,7 +78,7 @@ export type OptionsT = {
|
|
|
69
78
|
noCsp?: boolean;
|
|
70
79
|
staticCacheSize?: number;
|
|
71
80
|
ssrTimeout?: number;
|
|
72
|
-
staticCacheController?: (req: Request) => CacheRefT;
|
|
81
|
+
staticCacheController?: (req: Request) => CacheRefT | null | undefined;
|
|
73
82
|
};
|
|
74
83
|
/**
|
|
75
84
|
* Creates the middleware.
|
|
@@ -26,16 +26,15 @@ export declare function getDefaultCspSettings(): {
|
|
|
26
26
|
[x: string]: string[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
type ServerT = Express & {
|
|
29
|
+
export type ServerT = Express & {
|
|
30
30
|
logger: LoggerI;
|
|
31
31
|
};
|
|
32
32
|
export type OptionsT = RendererOptionsT & {
|
|
33
|
-
beforeExpressJsError?: (server: ServerT) => Promise<boolean
|
|
34
|
-
beforeExpressJsSetup?: (server: ServerT) => Promise<void
|
|
33
|
+
beforeExpressJsError?: (server: ServerT) => boolean | Promise<boolean | void> | void;
|
|
34
|
+
beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;
|
|
35
35
|
cspSettingsHook?: (defaultOptions: CspOptionsT, req: Request) => CspOptionsT;
|
|
36
36
|
devMode?: boolean;
|
|
37
37
|
httpsRedirect?: boolean;
|
|
38
38
|
onExpressJsSetup?: (server: ServerT) => Promise<void> | void;
|
|
39
39
|
};
|
|
40
40
|
export default function factory(webpackConfig: Configuration, options: OptionsT): Promise<ServerT>;
|
|
41
|
-
export {};
|
|
@@ -78,16 +78,9 @@ declare class ErrorWithStatus extends Error {
|
|
|
78
78
|
*/
|
|
79
79
|
export declare function newError(message: string, statusCode?: CODES): ErrorWithStatus;
|
|
80
80
|
/**
|
|
81
|
-
* ```js
|
|
82
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
83
|
-
* const { fail } = server.errors;
|
|
84
|
-
* ```
|
|
85
81
|
* Throws an error with given message and HTTP status code.
|
|
86
|
-
* @param message Error message.
|
|
87
|
-
* @param [statusCode=500] HTTP error code. Defaults to 500 (Internal
|
|
88
|
-
* Server Error).
|
|
89
82
|
*/
|
|
90
|
-
export declare function fail(message: string, statusCode?: CODES):
|
|
83
|
+
export declare function fail(message: string, statusCode?: CODES): never;
|
|
91
84
|
/**
|
|
92
85
|
* ```js
|
|
93
86
|
* import { server } from '@dr.pogodin/react-utils';
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.40.
|
|
2
|
+
"version": "1.40.9",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"url": "https://github.com/birdofpreyru/react-utils/issues"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/runtime": "^7.25.
|
|
11
|
+
"@babel/runtime": "^7.25.7",
|
|
12
12
|
"@dr.pogodin/babel-plugin-react-css-modules": "^6.13.2",
|
|
13
|
-
"@dr.pogodin/csurf": "^1.
|
|
13
|
+
"@dr.pogodin/csurf": "^1.14.0",
|
|
14
14
|
"@dr.pogodin/js-utils": "^0.0.12",
|
|
15
15
|
"@dr.pogodin/react-global-state": "^0.17.4",
|
|
16
16
|
"@dr.pogodin/react-themes": "^1.7.0",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"commander": "^12.1.0",
|
|
20
20
|
"compression": "^1.7.4",
|
|
21
21
|
"config": "^3.3.12",
|
|
22
|
-
"cookie": "^0.
|
|
23
|
-
"cookie-parser": "^1.4.
|
|
22
|
+
"cookie": "^1.0.1",
|
|
23
|
+
"cookie-parser": "^1.4.7",
|
|
24
24
|
"cross-env": "^7.0.3",
|
|
25
25
|
"dayjs": "^1.11.13",
|
|
26
|
-
"express": "^4.21.
|
|
27
|
-
"helmet": "^
|
|
26
|
+
"express": "^4.21.1",
|
|
27
|
+
"helmet": "^8.0.0",
|
|
28
28
|
"http-status-codes": "^2.3.0",
|
|
29
29
|
"joi": "^17.13.3",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
@@ -35,27 +35,27 @@
|
|
|
35
35
|
"react": "^18.3.1",
|
|
36
36
|
"react-dom": "^18.3.1",
|
|
37
37
|
"react-helmet": "^6.1.0",
|
|
38
|
-
"react-router-dom": "^6.
|
|
38
|
+
"react-router-dom": "^6.27.0",
|
|
39
39
|
"request-ip": "^3.3.0",
|
|
40
40
|
"rimraf": "^6.0.0",
|
|
41
41
|
"serialize-javascript": "^6.0.2",
|
|
42
42
|
"serve-favicon": "^2.5.0",
|
|
43
43
|
"source-map-support": "^0.5.21",
|
|
44
44
|
"uuid": "^10.0.0",
|
|
45
|
-
"winston": "^3.
|
|
45
|
+
"winston": "^3.15.0"
|
|
46
46
|
},
|
|
47
47
|
"description": "Collection of generic ReactJS components and utils",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@babel/cli": "^7.25.
|
|
50
|
-
"@babel/core": "^7.25.
|
|
51
|
-
"@babel/eslint-parser": "^7.25.
|
|
52
|
-
"@babel/eslint-plugin": "^7.25.
|
|
53
|
-
"@babel/node": "^7.25.
|
|
54
|
-
"@babel/plugin-transform-runtime": "^7.25.
|
|
55
|
-
"@babel/preset-env": "^7.25.
|
|
56
|
-
"@babel/preset-react": "^7.
|
|
57
|
-
"@babel/preset-typescript": "^7.
|
|
58
|
-
"@babel/register": "^7.
|
|
49
|
+
"@babel/cli": "^7.25.7",
|
|
50
|
+
"@babel/core": "^7.25.8",
|
|
51
|
+
"@babel/eslint-parser": "^7.25.8",
|
|
52
|
+
"@babel/eslint-plugin": "^7.25.7",
|
|
53
|
+
"@babel/node": "^7.25.7",
|
|
54
|
+
"@babel/plugin-transform-runtime": "^7.25.7",
|
|
55
|
+
"@babel/preset-env": "^7.25.8",
|
|
56
|
+
"@babel/preset-react": "^7.25.7",
|
|
57
|
+
"@babel/preset-typescript": "^7.25.7",
|
|
58
|
+
"@babel/register": "^7.25.7",
|
|
59
59
|
"@dr.pogodin/babel-plugin-transform-assets": "^1.2.2",
|
|
60
60
|
"@dr.pogodin/babel-preset-svgr": "^1.8.0",
|
|
61
61
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
|
|
@@ -70,12 +70,12 @@
|
|
|
70
70
|
"@types/csurf": "^1.11.5",
|
|
71
71
|
"@types/express": "^4.17.21",
|
|
72
72
|
"@types/jest": "^29.5.13",
|
|
73
|
-
"@types/lodash": "^4.17.
|
|
73
|
+
"@types/lodash": "^4.17.10",
|
|
74
74
|
"@types/morgan": "^1.9.9",
|
|
75
75
|
"@types/node-forge": "^1.3.11",
|
|
76
76
|
"@types/pretty": "^2.0.3",
|
|
77
|
-
"@types/react": "^18.3.
|
|
78
|
-
"@types/react-dom": "^18.3.
|
|
77
|
+
"@types/react": "^18.3.11",
|
|
78
|
+
"@types/react-dom": "^18.3.1",
|
|
79
79
|
"@types/react-helmet": "^6.1.11",
|
|
80
80
|
"@types/request-ip": "^0.0.41",
|
|
81
81
|
"@types/serialize-javascript": "^5.0.4",
|
|
@@ -85,47 +85,47 @@
|
|
|
85
85
|
"@types/webpack": "^5.28.5",
|
|
86
86
|
"autoprefixer": "^10.4.20",
|
|
87
87
|
"babel-jest": "^29.7.0",
|
|
88
|
-
"babel-loader": "^9.1
|
|
88
|
+
"babel-loader": "^9.2.1",
|
|
89
89
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
90
90
|
"core-js": "^3.38.1",
|
|
91
91
|
"css-loader": "^7.1.2",
|
|
92
92
|
"css-minimizer-webpack-plugin": "^7.0.0",
|
|
93
|
-
"eslint": "^8.57.
|
|
93
|
+
"eslint": "^8.57.1",
|
|
94
94
|
"eslint-config-airbnb": "^19.0.4",
|
|
95
95
|
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
96
96
|
"eslint-import-resolver-babel-module": "^5.3.2",
|
|
97
|
-
"eslint-plugin-import": "^2.
|
|
97
|
+
"eslint-plugin-import": "^2.31.0",
|
|
98
98
|
"eslint-plugin-jest": "^28.8.3",
|
|
99
99
|
"eslint-plugin-jsx-a11y": "^6.10.0",
|
|
100
|
-
"eslint-plugin-react": "^7.
|
|
100
|
+
"eslint-plugin-react": "^7.37.1",
|
|
101
101
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
102
102
|
"identity-obj-proxy": "^3.0.0",
|
|
103
103
|
"jest": "^29.7.0",
|
|
104
104
|
"jest-environment-jsdom": "^29.7.0",
|
|
105
|
-
"memfs": "^4.
|
|
105
|
+
"memfs": "^4.13.0",
|
|
106
106
|
"mini-css-extract-plugin": "^2.9.1",
|
|
107
107
|
"mockdate": "^3.0.5",
|
|
108
108
|
"nodelist-foreach-polyfill": "^1.2.0",
|
|
109
|
-
"postcss": "^8.4.
|
|
109
|
+
"postcss": "^8.4.47",
|
|
110
110
|
"postcss-loader": "^8.1.1",
|
|
111
111
|
"postcss-scss": "^4.0.9",
|
|
112
112
|
"pretty": "^2.0.0",
|
|
113
113
|
"react-refresh": "^0.14.2",
|
|
114
114
|
"regenerator-runtime": "^0.14.1",
|
|
115
115
|
"resolve-url-loader": "^5.0.0",
|
|
116
|
-
"sass": "^1.
|
|
117
|
-
"sass-loader": "^16.0.
|
|
116
|
+
"sass": "^1.79.5",
|
|
117
|
+
"sass-loader": "^16.0.2",
|
|
118
118
|
"sitemap": "^8.0.0",
|
|
119
119
|
"source-map-loader": "^5.0.0",
|
|
120
|
-
"stylelint": "^16.
|
|
120
|
+
"stylelint": "^16.10.0",
|
|
121
121
|
"stylelint-config-standard-scss": "^13.1.0",
|
|
122
122
|
"supertest": "^7.0.0",
|
|
123
123
|
"tsc-alias": "^1.8.10",
|
|
124
124
|
"tstyche": "^2.1.1",
|
|
125
125
|
"typed-scss-modules": "^8.0.1",
|
|
126
|
-
"typescript": "^5.6.
|
|
127
|
-
"typescript-eslint": "^8.
|
|
128
|
-
"webpack": "^5.
|
|
126
|
+
"typescript": "^5.6.3",
|
|
127
|
+
"typescript-eslint": "^8.8.1",
|
|
128
|
+
"webpack": "^5.95.0",
|
|
129
129
|
"webpack-dev-middleware": "^7.4.2",
|
|
130
130
|
"webpack-hot-middleware": "^2.26.1",
|
|
131
131
|
"webpack-merge": "^6.0.1",
|
package/src/index.ts
CHANGED
|
@@ -2,9 +2,9 @@ import 'styles/global.scss';
|
|
|
2
2
|
|
|
3
3
|
import { webpack } from 'utils';
|
|
4
4
|
|
|
5
|
-
import type
|
|
5
|
+
import type ServerFactoryT from './server';
|
|
6
6
|
|
|
7
|
-
const server = webpack.requireWeak('./server', __dirname) as (typeof
|
|
7
|
+
const server = webpack.requireWeak('./server', __dirname) as (typeof ServerFactoryT) | null;
|
|
8
8
|
|
|
9
9
|
const client = server ? undefined : require('./client').default;
|
|
10
10
|
|
|
@@ -29,6 +29,14 @@ export {
|
|
|
29
29
|
|
|
30
30
|
export * from 'components';
|
|
31
31
|
|
|
32
|
+
export {
|
|
33
|
+
type BeforeRenderResT,
|
|
34
|
+
type BeforeRenderT,
|
|
35
|
+
type ConfigT,
|
|
36
|
+
type ServerSsrContext,
|
|
37
|
+
type ServerT,
|
|
38
|
+
} from './server';
|
|
39
|
+
|
|
32
40
|
export {
|
|
33
41
|
type Listener,
|
|
34
42
|
type Theme,
|
package/src/server/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { type Configuration } from 'webpack';
|
|
|
19
19
|
|
|
20
20
|
import serverFactory, {
|
|
21
21
|
type OptionsT as ServerOptionsT,
|
|
22
|
+
type ServerT,
|
|
22
23
|
getDefaultCspSettings,
|
|
23
24
|
} from './server';
|
|
24
25
|
|
|
@@ -26,7 +27,14 @@ import { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';
|
|
|
26
27
|
|
|
27
28
|
import { errors } from './utils';
|
|
28
29
|
|
|
29
|
-
export {
|
|
30
|
+
export {
|
|
31
|
+
type BeforeRenderResT,
|
|
32
|
+
type BeforeRenderT,
|
|
33
|
+
type ConfigT,
|
|
34
|
+
type ServerSsrContext,
|
|
35
|
+
} from './renderer';
|
|
36
|
+
|
|
37
|
+
export { errors, getDefaultCspSettings, type ServerT };
|
|
30
38
|
|
|
31
39
|
/**
|
|
32
40
|
* Normalizes a port into a number, string, or false.
|
package/src/server/renderer.tsx
CHANGED
|
@@ -66,7 +66,7 @@ export enum SCRIPT_LOCATIONS {
|
|
|
66
66
|
HEAD_OPEN = 'HEAD_OPEN',
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
class ServerSsrContext<StateT>
|
|
69
|
+
export class ServerSsrContext<StateT>
|
|
70
70
|
extends SsrContext<StateT>
|
|
71
71
|
implements SsrContextT<StateT> {
|
|
72
72
|
chunkGroups: ChunkGroupsT;
|
|
@@ -242,17 +242,17 @@ export function newDefaultLogger({
|
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
type ConfigT = {
|
|
245
|
+
export type ConfigT = {
|
|
246
246
|
[key: string]: ConfigT | string;
|
|
247
247
|
};
|
|
248
248
|
|
|
249
|
-
type BeforeRenderResT = {
|
|
249
|
+
export type BeforeRenderResT = {
|
|
250
250
|
configToInject?: ConfigT;
|
|
251
251
|
extraScripts?: Array<ScriptT | string>;
|
|
252
252
|
initialState?: any;
|
|
253
253
|
};
|
|
254
254
|
|
|
255
|
-
type BeforeRenderT =
|
|
255
|
+
export type BeforeRenderT =
|
|
256
256
|
(req: Request, config: ConfigT) => BeforeRenderResT | Promise<BeforeRenderResT>;
|
|
257
257
|
|
|
258
258
|
type CacheRefT = {
|
|
@@ -271,7 +271,7 @@ export type OptionsT = {
|
|
|
271
271
|
noCsp?: boolean;
|
|
272
272
|
staticCacheSize?: number;
|
|
273
273
|
ssrTimeout?: number;
|
|
274
|
-
staticCacheController?: (req: Request) => CacheRefT;
|
|
274
|
+
staticCacheController?: (req: Request) => CacheRefT | null | undefined;
|
|
275
275
|
};
|
|
276
276
|
|
|
277
277
|
/**
|
|
@@ -354,7 +354,7 @@ export default function factory(
|
|
|
354
354
|
|
|
355
355
|
res.cookie('csrfToken', req.csrfToken());
|
|
356
356
|
|
|
357
|
-
let cacheRef: CacheRefT | undefined;
|
|
357
|
+
let cacheRef: CacheRefT | null | undefined;
|
|
358
358
|
if (cache) {
|
|
359
359
|
cacheRef = ops.staticCacheController!(req);
|
|
360
360
|
if (cacheRef) {
|
package/src/server/server.ts
CHANGED
|
@@ -102,13 +102,13 @@ export function getDefaultCspSettings() {
|
|
|
102
102
|
return cloneDeep(defaultCspSettings);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
type ServerT = Express & {
|
|
105
|
+
export type ServerT = Express & {
|
|
106
106
|
logger: LoggerI;
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
export type OptionsT = RendererOptionsT & {
|
|
110
|
-
beforeExpressJsError?: (server: ServerT) => Promise<boolean
|
|
111
|
-
beforeExpressJsSetup?: (server: ServerT) => Promise<void
|
|
110
|
+
beforeExpressJsError?: (server: ServerT) => boolean | Promise<boolean | void> | void;
|
|
111
|
+
beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;
|
|
112
112
|
cspSettingsHook?: (
|
|
113
113
|
defaultOptions: CspOptionsT,
|
|
114
114
|
req: Request,
|
|
@@ -96,16 +96,12 @@ export function newError(message: string, statusCode = CODES.INTERNAL_SERVER_ERR
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* ```js
|
|
100
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
101
|
-
* const { fail } = server.errors;
|
|
102
|
-
* ```
|
|
103
99
|
* Throws an error with given message and HTTP status code.
|
|
104
|
-
* @param message Error message.
|
|
105
|
-
* @param [statusCode=500] HTTP error code. Defaults to 500 (Internal
|
|
106
|
-
* Server Error).
|
|
107
100
|
*/
|
|
108
|
-
export function fail(
|
|
101
|
+
export function fail(
|
|
102
|
+
message: string,
|
|
103
|
+
statusCode: CODES = CODES.INTERNAL_SERVER_ERROR,
|
|
104
|
+
): never {
|
|
109
105
|
throw newError(message, statusCode);
|
|
110
106
|
}
|
|
111
107
|
|