@modern-js/prod-server 1.15.0 → 1.18.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @modern-js/prod-server
2
2
 
3
+ ## 1.18.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 3d5e3a5: chore: get api mode from bff core
8
+ chore: 从 bff core 中获取 api mode
9
+ - Updated dependencies [8280920]
10
+ - Updated dependencies [3d5e3a5]
11
+ - Updated dependencies [5227370]
12
+ - Updated dependencies [7928bae]
13
+ - @modern-js/utils@1.18.0
14
+ - @modern-js/server-core@1.18.0
15
+
16
+ ## 1.17.0
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [1b9176f]
21
+ - Updated dependencies [77d3a38]
22
+ - Updated dependencies [151329d]
23
+ - Updated dependencies [5af9472]
24
+ - Updated dependencies [6b6a534]
25
+ - Updated dependencies [6b43a2b]
26
+ - Updated dependencies [a7be124]
27
+ - Updated dependencies [31547b4]
28
+ - @modern-js/utils@1.17.0
29
+ - @modern-js/server-core@1.17.0
30
+
31
+ ## 1.16.0
32
+
33
+ ### Patch Changes
34
+
35
+ - 81c66e4a4: fix: compatibility issues of dev server in iOS 10
36
+
37
+ fix: 修复 dev server 代码在 iOS 10 下的兼容性问题
38
+
39
+ - Updated dependencies [641592f52]
40
+ - Updated dependencies [3904b30a5]
41
+ - Updated dependencies [1100dd58c]
42
+ - Updated dependencies [e04e6e76a]
43
+ - Updated dependencies [81c66e4a4]
44
+ - Updated dependencies [2c305b6f5]
45
+ - @modern-js/utils@1.16.0
46
+ - @modern-js/server-core@1.16.0
47
+
3
48
  ## 1.15.0
4
49
 
5
50
  ### Patch Changes
@@ -1,6 +1,36 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
1
7
  import { createProxyMiddleware } from 'http-proxy-middleware';
2
- import { formatProxyOptions } from '@modern-js/utils';
3
8
  import { debug } from "../utils";
9
+ export function formatProxyOptions(proxyOptions) {
10
+ const formattedProxy = [];
11
+
12
+ if (!Array.isArray(proxyOptions)) {
13
+ if ('target' in proxyOptions) {
14
+ formattedProxy.push(proxyOptions);
15
+ } else {
16
+ Array.prototype.push.apply(formattedProxy, Object.keys(proxyOptions).reduce((total, source) => {
17
+ const option = proxyOptions[source];
18
+ total.push(_objectSpread({
19
+ context: source,
20
+ changeOrigin: true,
21
+ logLevel: 'warn'
22
+ }, typeof option === 'string' ? {
23
+ target: option
24
+ } : option));
25
+ return total;
26
+ }, []));
27
+ }
28
+ } else {
29
+ formattedProxy.push(...proxyOptions);
30
+ }
31
+
32
+ return formattedProxy;
33
+ }
4
34
  export const createProxyHandler = proxyOptions => {
5
35
  debug('createProxyHandler', proxyOptions);
6
36
 
@@ -2,7 +2,7 @@ import { RUN_MODE } from "../constants";
2
2
  import { ModernServer } from "./modern-server";
3
3
 
4
4
  class ModernSSRServer extends ModernServer {
5
- prepareAPIHandler(_m, _) {
5
+ prepareAPIHandler(_) {
6
6
  return null;
7
7
  }
8
8
 
@@ -24,7 +24,7 @@ import { createErrorDocument, createMiddlewareCollecter, getStaticReg, mergeExte
24
24
  import * as reader from "../libs/render/reader";
25
25
  import { createProxyHandler } from "../libs/proxy";
26
26
  import { createContext } from "../libs/context";
27
- import { AGGRED_DIR, ApiServerMode, ERROR_DIGEST, ERROR_PAGE_TEXT, RUN_MODE } from "../constants";
27
+ import { AGGRED_DIR, ERROR_DIGEST, ERROR_PAGE_TEXT, RUN_MODE } from "../constants";
28
28
  import { createTemplateAPI } from "../libs/hook-api/template";
29
29
  import { createRouteAPI } from "../libs/hook-api/route";
30
30
  const API_DIR = './api';
@@ -257,11 +257,8 @@ export class ModernServer {
257
257
  }
258
258
 
259
259
  if (fs.existsSync(apiDir) && !onlyWeb) {
260
- const mode = fs.existsSync(path.join(apiDir, AGGRED_DIR.lambda)) ? ApiServerMode.frame : ApiServerMode.func;
261
- debug('exists api dir', mode); // if use lambda/, mean framework style of writing, then discard user extension
262
-
263
260
  const apiExtension = mergeExtension(pluginAPIExt);
264
- this.frameAPIHandler = await this.prepareAPIHandler(mode, apiExtension);
261
+ this.frameAPIHandler = await this.prepareAPIHandler(apiExtension);
265
262
  }
266
263
  }
267
264
 
@@ -278,7 +275,7 @@ export class ModernServer {
278
275
  });
279
276
  }
280
277
 
281
- async prepareAPIHandler(mode, extension) {
278
+ async prepareAPIHandler(extension) {
282
279
  const {
283
280
  workDir,
284
281
  runner,
@@ -290,7 +287,6 @@ export class ModernServer {
290
287
  const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
291
288
  return runner.prepareApiServer({
292
289
  pwd: workDir,
293
- mode,
294
290
  config: extension,
295
291
  prefix: Array.isArray(prefix) ? prefix[0] : prefix
296
292
  }, {
@@ -4,15 +4,46 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createProxyHandler = void 0;
7
+ exports.formatProxyOptions = formatProxyOptions;
7
8
 
8
9
  var _httpProxyMiddleware = require("http-proxy-middleware");
9
10
 
10
- var _utils = require("@modern-js/utils");
11
+ var _utils = require("../utils");
11
12
 
12
- var _utils2 = require("../utils");
13
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
+
15
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
+
17
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
+
19
+ function formatProxyOptions(proxyOptions) {
20
+ const formattedProxy = [];
21
+
22
+ if (!Array.isArray(proxyOptions)) {
23
+ if ('target' in proxyOptions) {
24
+ formattedProxy.push(proxyOptions);
25
+ } else {
26
+ Array.prototype.push.apply(formattedProxy, Object.keys(proxyOptions).reduce((total, source) => {
27
+ const option = proxyOptions[source];
28
+ total.push(_objectSpread({
29
+ context: source,
30
+ changeOrigin: true,
31
+ logLevel: 'warn'
32
+ }, typeof option === 'string' ? {
33
+ target: option
34
+ } : option));
35
+ return total;
36
+ }, []));
37
+ }
38
+ } else {
39
+ formattedProxy.push(...proxyOptions);
40
+ }
41
+
42
+ return formattedProxy;
43
+ }
13
44
 
14
45
  const createProxyHandler = proxyOptions => {
15
- (0, _utils2.debug)('createProxyHandler', proxyOptions);
46
+ (0, _utils.debug)('createProxyHandler', proxyOptions);
16
47
 
17
48
  if (!proxyOptions) {
18
49
  return null;
@@ -20,7 +51,7 @@ const createProxyHandler = proxyOptions => {
20
51
  // or an object in the form of { source: ProxyDetail }
21
52
 
22
53
 
23
- const formattedProxy = (0, _utils.formatProxyOptions)(proxyOptions);
54
+ const formattedProxy = formatProxyOptions(proxyOptions);
24
55
  const middlewares = formattedProxy.map(option => {
25
56
  const middleware = (0, _httpProxyMiddleware.createProxyMiddleware)(option.context, option); // eslint-disable-next-line consistent-return
26
57
 
@@ -10,7 +10,7 @@ var _constants = require("../constants");
10
10
  var _modernServer = require("./modern-server");
11
11
 
12
12
  class ModernSSRServer extends _modernServer.ModernServer {
13
- prepareAPIHandler(_m, _) {
13
+ prepareAPIHandler(_) {
14
14
  return null;
15
15
  }
16
16
 
@@ -293,11 +293,8 @@ class ModernServer {
293
293
  }
294
294
 
295
295
  if (_utils.fs.existsSync(apiDir) && !onlyWeb) {
296
- const mode = _utils.fs.existsSync(_path.default.join(apiDir, _constants.AGGRED_DIR.lambda)) ? _constants.ApiServerMode.frame : _constants.ApiServerMode.func;
297
- (0, _utils2.debug)('exists api dir', mode); // if use lambda/, mean framework style of writing, then discard user extension
298
-
299
296
  const apiExtension = (0, _utils2.mergeExtension)(pluginAPIExt);
300
- this.frameAPIHandler = await this.prepareAPIHandler(mode, apiExtension);
297
+ this.frameAPIHandler = await this.prepareAPIHandler(apiExtension);
301
298
  }
302
299
  }
303
300
 
@@ -314,7 +311,7 @@ class ModernServer {
314
311
  });
315
312
  }
316
313
 
317
- async prepareAPIHandler(mode, extension) {
314
+ async prepareAPIHandler(extension) {
318
315
  const {
319
316
  workDir,
320
317
  runner,
@@ -326,7 +323,6 @@ class ModernServer {
326
323
  const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
327
324
  return runner.prepareApiServer({
328
325
  pwd: workDir,
329
- mode,
330
326
  config: extension,
331
327
  prefix: Array.isArray(prefix) ? prefix[0] : prefix
332
328
  }, {
@@ -1,4 +1,5 @@
1
- import { NextFunction, BffProxyOptions } from '@modern-js/types';
1
+ import { ProxyDetail, NextFunction, BffProxyOptions } from '@modern-js/types';
2
2
  import { ModernServerContext } from './context';
3
3
  export type { BffProxyOptions };
4
+ export declare function formatProxyOptions(proxyOptions: BffProxyOptions): ProxyDetail[];
4
5
  export declare const createProxyHandler: (proxyOptions?: BffProxyOptions) => ((ctx: ModernServerContext, next: NextFunction) => Promise<void>)[] | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { BaseSSRServerContext } from '@modern-js/types/server';
2
3
  declare type MetaKeyMap = {
3
4
  header?: string[];
@@ -7,7 +7,6 @@ import { RouteMatchManager, ModernRouteInterface, ModernRoute } from '../libs/ro
7
7
  import { mergeExtension } from '../utils';
8
8
  import * as reader from '../libs/render/reader';
9
9
  import { ModernServerContext } from '../libs/context';
10
- import { ApiServerMode } from '../constants';
11
10
  declare type ModernServerHandler = (context: ModernServerContext, next: NextFunction) => Promise<void> | void;
12
11
  declare type ModernServerAsyncHandler = (context: ModernServerContext, next: NextFunction) => Promise<void>;
13
12
  export declare class ModernServer implements ModernServerInterface {
@@ -60,7 +59,7 @@ export declare class ModernServer implements ModernServerInterface {
60
59
  onlyWeb: boolean;
61
60
  }): Promise<void>;
62
61
  protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<Adapter>;
63
- protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<Adapter>;
62
+ protected prepareAPIHandler(extension: APIServerStartInput['config']): Promise<Adapter>;
64
63
  protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
65
64
  protected emitRouteHook(eventName: HookNames, input: {
66
65
  context: ModernServerContext;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.15.0",
14
+ "version": "1.18.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,9 +28,9 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/utils": "1.15.0",
31
+ "@modern-js/utils": "1.18.0",
32
32
  "@babel/compat-data": "^7.17.10",
33
- "@modern-js/server-core": "1.15.0",
33
+ "@modern-js/server-core": "1.18.0",
34
34
  "axios": "^0.24.0",
35
35
  "compare-versions": "^3.6.0",
36
36
  "cookie": "^0.4.2",
@@ -43,10 +43,10 @@
43
43
  "ua-parser-js": "^0.7.28"
44
44
  },
45
45
  "devDependencies": {
46
- "@modern-js/types": "1.15.0",
47
- "@modern-js/core": "1.15.0",
48
- "@scripts/jest-config": "1.15.0",
49
- "@scripts/build": "1.15.0",
46
+ "@modern-js/types": "1.18.0",
47
+ "@modern-js/core": "1.18.0",
48
+ "@scripts/jest-config": "1.18.0",
49
+ "@scripts/build": "1.18.0",
50
50
  "@types/cookie": "^0.4.1",
51
51
  "@types/jest": "^27",
52
52
  "@types/lru-cache": "^5.1.1",