@umijs/server 3.5.38 → 3.5.39

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.
@@ -12,6 +12,7 @@ interface IServerProxyConfigItem extends ProxyOptions {
12
12
  }
13
13
  declare type IServerProxyConfig = IServerProxyConfigItem | Record<string, IServerProxyConfigItem> | (IServerProxyConfigItem | (() => IServerProxyConfigItem))[] | null;
14
14
  export interface IHttps extends ServerOptions {
15
+ http2?: boolean;
15
16
  }
16
17
  export interface IServerOpts {
17
18
  afterMiddlewares?: RequestHandler<any>[];
@@ -95,6 +95,16 @@ function http() {
95
95
  return data;
96
96
  }
97
97
 
98
+ function https() {
99
+ const data = _interopRequireWildcard(require("https"));
100
+
101
+ https = function https() {
102
+ return data;
103
+ };
104
+
105
+ return data;
106
+ }
107
+
98
108
  function url() {
99
109
  const data = _interopRequireWildcard(require("url"));
100
110
 
@@ -179,11 +189,30 @@ class Server {
179
189
  logger.warn('Providing custom spdy server options is deprecated and will be removed in the next major version.');
180
190
  return credential;
181
191
  } else {
182
- return _objectSpread({
192
+ var _this$opts$https;
193
+
194
+ // If user config forces using http2, we should configure spdy
195
+ if (process.env.HTTP2) {
196
+ return _objectSpread(_objectSpread({}, credential), {}, {
197
+ spdy: {
198
+ protocols: ['h2', 'http/1.1']
199
+ }
200
+ });
201
+ } // If user config explicitly sets http2 to false, we should not configure spdy
202
+
203
+
204
+ if (typeof this.opts.https === 'object' && ((_this$opts$https = this.opts.https) === null || _this$opts$https === void 0 ? void 0 : _this$opts$https.http2) === false) {
205
+ return _objectSpread(_objectSpread({}, credential), {}, {
206
+ spdy: undefined
207
+ });
208
+ } // Default to use spdy(google's http2 implementation) when https is enabled
209
+
210
+
211
+ return _objectSpread(_objectSpread({}, credential), {}, {
183
212
  spdy: {
184
213
  protocols: ['h2', 'http/1.1']
185
214
  }
186
- }, credential);
215
+ });
187
216
  }
188
217
  }
189
218
 
@@ -426,8 +455,12 @@ class Server {
426
455
  const httpsOpts = this.getHttpsOptions();
427
456
 
428
457
  if (httpsOpts) {
429
- // http2 using spdy, HTTP/2 by default when using https
430
- this.listeningApp = _spdy().default.createServer(httpsOpts, this.app);
458
+ // If spdy is configured, use spdy server
459
+ if (httpsOpts.spdy) {
460
+ this.listeningApp = _spdy().default.createServer(httpsOpts, this.app); // Otherwise fallback to plain https server
461
+ } else {
462
+ this.listeningApp = https().createServer(httpsOpts, this.app);
463
+ }
431
464
  } else {
432
465
  this.listeningApp = http().createServer(this.app);
433
466
  }
@@ -69,14 +69,26 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
69
69
 
70
70
  const logger = new (_core().Logger)('@umijs/server:utils');
71
71
 
72
- const getCredentials = opts => {
73
- const https = opts.https;
74
- const defautlServerOptions = {
72
+ function useDefaultKeyCertOptions(httpsOptions) {
73
+ const defaultKeyCertOptions = {
75
74
  key: (0, _path().join)(__dirname, 'cert', 'key.pem'),
76
75
  cert: (0, _path().join)(__dirname, 'cert', 'cert.pem')
77
- }; // custom cert using https: { key: '', cert: '' }
76
+ };
78
77
 
79
- const serverOptions = https === true ? defautlServerOptions : https;
78
+ if (httpsOptions === true) {
79
+ return defaultKeyCertOptions;
80
+ }
81
+
82
+ if (typeof httpsOptions === 'object') {
83
+ return _objectSpread(_objectSpread({}, defaultKeyCertOptions), httpsOptions);
84
+ }
85
+
86
+ return {};
87
+ }
88
+
89
+ const getCredentials = opts => {
90
+ const https = opts.https;
91
+ const serverOptions = useDefaultKeyCertOptions(https);
80
92
 
81
93
  if (!(serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.key) || !(serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.cert)) {
82
94
  const err = new Error(`Both options.https.key and options.https.cert are required.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/server",
3
- "version": "3.5.38",
3
+ "version": "3.5.39",
4
4
  "description": "@umijs/server",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,8 +24,8 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@umijs/core": "3.5.38",
28
- "@umijs/deps": "3.5.38",
29
- "@umijs/utils": "3.5.38"
27
+ "@umijs/core": "3.5.39",
28
+ "@umijs/deps": "3.5.39",
29
+ "@umijs/utils": "3.5.39"
30
30
  }
31
31
  }