@modern-js/server 1.1.4 → 1.2.1-beta.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/js/modern/index.js +1 -7
  3. package/dist/js/modern/libs/context/context.js +16 -11
  4. package/dist/js/modern/libs/context/index.js +1 -7
  5. package/dist/js/modern/libs/{measure.js → metrics.js} +2 -2
  6. package/dist/js/modern/libs/proxy.js +1 -1
  7. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +1 -2
  8. package/dist/js/modern/libs/render/index.js +6 -2
  9. package/dist/js/modern/libs/render/reader.js +8 -11
  10. package/dist/js/modern/libs/render/ssr.js +3 -2
  11. package/dist/js/modern/libs/route/index.js +2 -1
  12. package/dist/js/modern/libs/route/route.js +1 -1
  13. package/dist/js/modern/server/dev-server/dev-server.js +11 -2
  14. package/dist/js/modern/server/index.js +5 -3
  15. package/dist/js/modern/server/modern-server.js +22 -13
  16. package/dist/js/modern/utils.js +1 -9
  17. package/dist/js/node/index.js +1 -49
  18. package/dist/js/node/libs/context/context.js +16 -11
  19. package/dist/js/node/libs/context/index.js +1 -7
  20. package/dist/js/node/libs/{measure.js → metrics.js} +3 -3
  21. package/dist/js/node/libs/proxy.js +1 -1
  22. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +1 -2
  23. package/dist/js/node/libs/render/index.js +6 -2
  24. package/dist/js/node/libs/render/reader.js +8 -11
  25. package/dist/js/node/libs/render/ssr.js +3 -2
  26. package/dist/js/node/libs/route/index.js +6 -0
  27. package/dist/js/node/libs/route/route.js +1 -1
  28. package/dist/js/node/server/dev-server/dev-server.js +11 -2
  29. package/dist/js/node/server/index.js +5 -3
  30. package/dist/js/node/server/modern-server.js +22 -13
  31. package/dist/js/node/utils.js +2 -12
  32. package/dist/types/index.d.ts +1 -3
  33. package/dist/types/libs/context/context.d.ts +10 -10
  34. package/dist/types/libs/context/index.d.ts +1 -8
  35. package/dist/types/libs/metrics.d.ts +3 -0
  36. package/dist/types/libs/render/index.d.ts +10 -1
  37. package/dist/types/libs/render/ssr.d.ts +2 -1
  38. package/dist/types/libs/render/type.d.ts +2 -21
  39. package/dist/types/libs/route/index.d.ts +2 -1
  40. package/dist/types/libs/route/route.d.ts +2 -10
  41. package/dist/types/server/modern-server.d.ts +4 -4
  42. package/dist/types/type.d.ts +12 -5
  43. package/dist/types/utils.d.ts +1 -2
  44. package/package.json +11 -9
  45. package/src/index.ts +2 -8
  46. package/src/libs/context/context.ts +18 -13
  47. package/src/libs/context/index.ts +2 -6
  48. package/src/libs/{measure.ts → metrics.ts} +3 -3
  49. package/src/libs/proxy.ts +1 -1
  50. package/src/libs/render/cache/__tests__/cache.test.ts +2 -2
  51. package/src/libs/render/index.ts +21 -11
  52. package/src/libs/render/reader.ts +8 -8
  53. package/src/libs/render/ssr.ts +5 -1
  54. package/src/libs/render/type.ts +2 -17
  55. package/src/libs/route/index.ts +2 -1
  56. package/src/libs/route/route.ts +4 -20
  57. package/src/server/dev-server/dev-server.ts +8 -2
  58. package/src/server/index.ts +3 -3
  59. package/src/server/modern-server.ts +22 -15
  60. package/src/type.ts +14 -5
  61. package/src/utils.ts +0 -14
  62. package/tests/.eslintrc.js +6 -0
  63. package/tests/context.test.ts +41 -0
  64. package/tests/fixtures/hosting-files/static/index.js +1 -0
  65. package/tests/fixtures/pure/modern.config.js +5 -0
  66. package/tests/fixtures/pure/package.json +21 -0
  67. package/tests/fixtures/pure/src/App.css +119 -0
  68. package/tests/fixtures/pure/src/App.tsx +43 -0
  69. package/tests/fixtures/pure/tsconfig.json +13 -0
  70. package/tests/fixtures/route-spec/index.json +29 -0
  71. package/tests/helper.ts +8 -0
  72. package/tests/hook.test.ts +44 -0
  73. package/tests/middleware.test.ts +178 -0
  74. package/tests/route.test.ts +54 -0
  75. package/tests/server.test.ts +89 -0
  76. package/tests/tsconfig.json +14 -0
  77. package/tests/utils.test.ts +40 -0
  78. package/dist/types/libs/measure.d.ts +0 -3
@@ -26,9 +26,9 @@ const createCacheItem = async (filepath, mtime) => {
26
26
  };
27
27
 
28
28
  class LruReader {
29
+ // private timer?: NodeJS.Timeout;
29
30
  constructor() {
30
31
  this.cache = void 0;
31
- this.timer = void 0;
32
32
  this.cache = new _lruCache.default({
33
33
  max: 256 * MB,
34
34
  length: getContentLength,
@@ -37,14 +37,12 @@ class LruReader {
37
37
  });
38
38
  }
39
39
 
40
- init() {
41
- this.timeTask();
40
+ init() {// this.timeTask();
42
41
  }
43
42
 
44
- close() {
45
- if (this.timer) {
46
- clearInterval(this.timer);
47
- }
43
+ close() {// if (this.timer) {
44
+ // clearInterval(this.timer);
45
+ // }
48
46
  }
49
47
 
50
48
  async read(filepath) {
@@ -105,11 +103,10 @@ class LruReader {
105
103
  cache.del(filepath);
106
104
  }
107
105
  }
108
- }
106
+ } // private timeTask() {
107
+ // this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
108
+ // }
109
109
 
110
- timeTask() {
111
- this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
112
- }
113
110
 
114
111
  }
115
112
 
@@ -15,7 +15,7 @@ var _cache = _interopRequireDefault(require("./cache"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- const render = async (ctx, renderOptions) => {
18
+ const render = async (ctx, renderOptions, runner) => {
19
19
  const {
20
20
  bundle,
21
21
  distDir,
@@ -40,8 +40,9 @@ const render = async (ctx, renderOptions) => {
40
40
  distDir,
41
41
  staticGenerate,
42
42
  logger: ctx.logger,
43
- measure: ctx.measure
43
+ metrics: ctx.metrics
44
44
  };
45
+ runner.extendSSRContext(context);
45
46
 
46
47
  const serverRender = require(bundleJS)[_utils.SERVER_RENDER_FUNCTION_NAME];
47
48
 
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.RouteMatchManager = void 0;
7
+ Object.defineProperty(exports, "RouteMatcher", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _matcher.RouteMatcher;
11
+ }
12
+ });
7
13
 
8
14
  var _matcher = require("./matcher");
9
15
 
@@ -17,7 +17,7 @@ class ModernRoute {
17
17
  this.isSSR = void 0;
18
18
  this.isSPA = void 0;
19
19
  this.enableModernMode = void 0;
20
- this.entryName = routeSpec.entryName;
20
+ this.entryName = routeSpec.entryName || '';
21
21
  this.urlPath = routeSpec.urlPath;
22
22
  this.entryPath = routeSpec.entryPath || '';
23
23
  this.isSSR = routeSpec.isSSR || false;
@@ -41,6 +41,12 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
41
41
 
42
42
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
43
 
44
+ 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; }
45
+
46
+ 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; }
47
+
48
+ 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; }
49
+
44
50
  const DEFAULT_DEV_OPTIONS = {
45
51
  client: {
46
52
  port: '8080',
@@ -53,6 +59,7 @@ const DEFAULT_DEV_OPTIONS = {
53
59
  dev: {
54
60
  writeToDisk: true
55
61
  },
62
+ watch: true,
56
63
  hot: true,
57
64
  liveReload: true
58
65
  };
@@ -70,7 +77,7 @@ class ModernDevServer extends _modernServer.ModernServer {
70
77
  this.devMiddleware = void 0;
71
78
  this.compiler = options.compiler; // set dev server options, like webpack-dev-server
72
79
 
73
- this.dev = typeof options.dev === 'boolean' ? DEFAULT_DEV_OPTIONS : options.dev;
80
+ this.dev = typeof options.dev === 'boolean' ? DEFAULT_DEV_OPTIONS : _objectSpread(_objectSpread({}, DEFAULT_DEV_OPTIONS), options.dev);
74
81
  (0, _register.enableRegister)(this.pwd, this.conf);
75
82
  } // Complete the preparation of services
76
83
 
@@ -119,7 +126,9 @@ class ModernDevServer extends _modernServer.ModernServer {
119
126
 
120
127
  await super.init(runner); // watch mock/ server/ api/ dir file change
121
128
 
122
- this.startWatcher();
129
+ if (this.dev.watch) {
130
+ this.startWatcher();
131
+ }
123
132
  }
124
133
 
125
134
  ready(options = {}) {
@@ -17,7 +17,7 @@ var _modernServer = require("./modern-server");
17
17
 
18
18
  var _modernServerSplit = require("./modern-server-split");
19
19
 
20
- var _measure = require("../libs/measure");
20
+ var _metrics = require("../libs/metrics");
21
21
 
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
@@ -52,7 +52,7 @@ class Server {
52
52
  options
53
53
  } = this;
54
54
  options.logger = options.logger || _utils.logger;
55
- options.measure = options.measure || _measure.measure; // initialize server
55
+ options.metrics = options.metrics || _metrics.metrics; // initialize server
56
56
 
57
57
  if (options.dev) {
58
58
  this.server = this.createDevServer();
@@ -137,10 +137,12 @@ class Server {
137
137
  const appContext = await this.initAppContext();
138
138
 
139
139
  _serverPlugin.serverManager.run(() => {
140
+ var _options$config$outpu;
141
+
140
142
  _core.ConfigContext.set(this.options.config);
141
143
 
142
144
  _core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
143
- distDirectory: _path.default.join(options.pwd, options.config.output.path || 'dist')
145
+ distDirectory: _path.default.join(options.pwd, ((_options$config$outpu = options.config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.path) || 'dist')
144
146
  }));
145
147
  });
146
148
 
@@ -71,9 +71,11 @@ class ModernServer {
71
71
  routes,
72
72
  staticGenerate,
73
73
  logger,
74
- measure,
74
+ metrics,
75
75
  proxyTarget
76
76
  }) {
77
+ var _config$output;
78
+
77
79
  this.pwd = void 0;
78
80
  this.distDir = void 0;
79
81
  this.workDir = void 0;
@@ -83,26 +85,26 @@ class ModernServer {
83
85
  this.presetRoutes = void 0;
84
86
  this.runner = void 0;
85
87
  this.logger = void 0;
86
- this.measure = void 0;
88
+ this.metrics = void 0;
87
89
  this.proxyTarget = void 0;
88
90
  this.isDev = false;
89
91
  this.staticFileHandler = void 0;
90
92
  this.routeRenderHandler = void 0;
91
93
  this.frameWebHandler = null;
92
94
  this.frameAPIHandler = null;
95
+ this.proxyHandler = null;
93
96
  this._handler = void 0;
94
97
  this.staticGenerate = false;
95
- this.proxyHandler = null;
96
98
 
97
99
  require('ignore-styles');
98
100
 
99
101
  this.isDev = Boolean(dev);
100
102
  this.pwd = pwd;
101
- this.distDir = _path.default.join(pwd, config.output.path || 'dist');
103
+ this.distDir = _path.default.join(pwd, ((_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.path) || 'dist');
102
104
  this.workDir = this.isDev ? pwd : this.distDir;
103
105
  this.conf = config;
104
106
  this.logger = logger;
105
- this.measure = measure;
107
+ this.metrics = metrics;
106
108
  this.router = new _route.RouteMatchManager();
107
109
  this.presetRoutes = routes;
108
110
  this.proxyTarget = proxyTarget;
@@ -158,7 +160,7 @@ class ModernServer {
158
160
  const {
159
161
  favicon,
160
162
  faviconByEntries
161
- } = this.conf.output;
163
+ } = this.conf.output || {};
162
164
  const favicons = this.prepareFavicons(favicon, faviconByEntries); // Only work when without setting `assetPrefix`.
163
165
  // Setting `assetPrefix` means these resources should be uploaded to CDN.
164
166
 
@@ -348,7 +350,11 @@ class ModernServer {
348
350
  }
349
351
 
350
352
  async handleWeb(context, route) {
351
- return this.routeRenderHandler(context, route);
353
+ return this.routeRenderHandler({
354
+ ctx: context,
355
+ route,
356
+ runner: this.runner
357
+ });
352
358
  }
353
359
 
354
360
  verifyMatch(_c, _m) {// empty
@@ -367,7 +373,7 @@ class ModernServer {
367
373
  context
368
374
  }); // match routes in the route spec
369
375
 
370
- const matched = this.router.match(context.url);
376
+ const matched = this.router.match(context.path);
371
377
 
372
378
  if (!matched) {
373
379
  this.render404(context);
@@ -555,10 +561,9 @@ class ModernServer {
555
561
  requestHandler(req, res, next = () => {// empty
556
562
  }) {
557
563
  res.statusCode = 200;
558
- const context = (0, _context.createContext)(req, res, {
559
- logger: this.logger,
560
- measure: this.measure
561
- });
564
+ req.logger = req.logger || this.logger;
565
+ req.metrics = req.metrics || this.metrics;
566
+ const context = (0, _context.createContext)(req, res);
562
567
 
563
568
  try {
564
569
  this._handler(context, next);
@@ -590,7 +595,11 @@ class ModernServer {
590
595
 
591
596
  if (entryName === status.toString() || entryName === '_error') {
592
597
  try {
593
- const file = await this.routeRenderHandler(context, route);
598
+ const file = await this.routeRenderHandler({
599
+ route,
600
+ ctx: context,
601
+ runner: this.runner
602
+ });
594
603
 
595
604
  if (file) {
596
605
  context.res.end(file.content);
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.applyMixins = applyMixins;
7
6
  exports.toMessage = exports.noop = exports.mergeExtension = exports.createErrorDocument = void 0;
8
7
 
9
8
  const mergeExtension = users => {
@@ -64,15 +63,6 @@ const createErrorDocument = (status, text) => {
64
63
  </body>
65
64
  </html>
66
65
  `;
67
- }; // This can live anywhere in your codebase:
68
-
69
-
70
- exports.createErrorDocument = createErrorDocument;
66
+ };
71
67
 
72
- function applyMixins(derivedCtor, constructors) {
73
- constructors.forEach(baseCtor => {
74
- Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
75
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
76
- });
77
- });
78
- }
68
+ exports.createErrorDocument = createErrorDocument;
@@ -1,10 +1,8 @@
1
1
  import { ModernServerOptions } from './type';
2
2
  import { Server } from './server';
3
- export * from './type';
4
- export * from './libs/context';
5
- export * from './libs/route';
6
3
  export type { SSRServerContext } from './libs/render/type';
7
4
  export { Server };
5
+ export type { ModernServerOptions };
8
6
 
9
7
  declare const _default: (options: ModernServerOptions) => Promise<Server>;
10
8
 
@@ -1,8 +1,14 @@
1
+ /// <reference path="../../type.d.ts" />
1
2
  /// <reference types="node" />
3
+ /// <reference types="node/http" />
2
4
  import { IncomingMessage, ServerResponse } from 'http';
3
5
  import { URL } from 'url';
4
6
  import qs from 'querystring';
5
- import type { ModernServerContext as ModernServerContextInterface, Measure, Logger } from '@modern-js/types/server';
7
+ import type { ModernServerContext as ModernServerContextInterface, Metrics, Logger } from '@modern-js/types/server';
8
+ export declare type ContextOptions = {
9
+ logger?: Logger;
10
+ metrics?: Metrics;
11
+ };
6
12
  export declare class ModernServerContext implements ModernServerContextInterface {
7
13
  /**
8
14
  * http request
@@ -19,18 +25,12 @@ export declare class ModernServerContext implements ModernServerContextInterface
19
25
 
20
26
  params: Record<string, string>;
21
27
  logger: Logger;
22
- measure?: Measure;
23
- constructor(req: IncomingMessage, res: ServerResponse, {
24
- logger,
25
- measure
26
- }: {
27
- logger: Logger;
28
- measure: Measure;
29
- });
28
+ metrics?: Metrics;
29
+ constructor(req: IncomingMessage, res: ServerResponse);
30
+ private bind;
30
31
  setParams(params: Record<string, string>): void;
31
32
  getReqHeader(key: string): string | string[];
32
33
  get headers(): import("http").IncomingHttpHeaders;
33
- set headers(val: import("http").IncomingHttpHeaders);
34
34
  get method(): string;
35
35
  get url(): string;
36
36
  set url(val: string);
@@ -1,11 +1,4 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
- import { Measure, Logger } from '../../type';
3
2
  import { ModernServerContext } from './context';
4
- export declare const createContext: (req: IncomingMessage, res: ServerResponse, {
5
- logger,
6
- measure
7
- }: {
8
- logger: Logger;
9
- measure: Measure;
10
- }) => ModernServerContext;
3
+ export declare const createContext: (req: IncomingMessage, res: ServerResponse) => ModernServerContext;
11
4
  export { ModernServerContext };
@@ -0,0 +1,3 @@
1
+ import { Metrics } from "../type.d";
2
+ declare const metrics: Metrics;
3
+ export { metrics };
@@ -1,10 +1,19 @@
1
1
  import { RenderResult } from '../../type';
2
2
  import { ModernRoute } from '../route';
3
3
  import { ModernServerContext } from '../context';
4
+ import { ServerHookRunner } from "../../type.d";
4
5
  export declare const createRenderHandler: ({
5
6
  distDir,
6
7
  staticGenerate
7
8
  }: {
8
9
  distDir: string;
9
10
  staticGenerate: boolean;
10
- }) => (ctx: ModernServerContext, route: ModernRoute) => Promise<RenderResult | null>;
11
+ }) => ({
12
+ ctx,
13
+ route,
14
+ runner
15
+ }: {
16
+ ctx: ModernServerContext;
17
+ route: ModernRoute;
18
+ runner: ServerHookRunner;
19
+ }) => Promise<RenderResult | null>;
@@ -1,9 +1,10 @@
1
1
  import { ModernServerContext } from '../context';
2
2
  import { RenderResult } from '../../type';
3
+ import { ServerHookRunner } from "../../type.d";
3
4
  export declare const render: (ctx: ModernServerContext, renderOptions: {
4
5
  distDir: string;
5
6
  bundle: string;
6
7
  template: string;
7
8
  entryName: string;
8
9
  staticGenerate: boolean;
9
- }) => Promise<RenderResult>;
10
+ }, runner: ServerHookRunner) => Promise<RenderResult>;
@@ -1,7 +1,5 @@
1
- /// <reference types="node" />
2
1
  /// <reference types="react" />
3
- import { IncomingHttpHeaders } from 'http';
4
- import { Measure, Logger } from '../../type';
2
+ import { BaseSSRServerContext } from '@modern-js/types/server';
5
3
  declare type MetaKeyMap = {
6
4
  header?: string[];
7
5
  query?: string[];
@@ -24,24 +22,7 @@ export declare enum RenderLevel {
24
22
  SERVER_PREFETCH = 1,
25
23
  SERVER_RENDER = 2,
26
24
  }
27
- export declare type SSRServerContext = {
28
- request: {
29
- params: Record<string, string>;
30
- pathname: string;
31
- query: Record<string, string>;
32
- headers: IncomingHttpHeaders;
33
- cookie?: string;
34
- };
35
- redirection: {
36
- url?: string;
37
- status?: number;
38
- };
39
- distDir: string;
40
- template: string;
41
- entryName: string;
42
- logger: Logger;
43
- measure?: Measure;
44
- loadableManifest?: string;
25
+ export declare type SSRServerContext = BaseSSRServerContext & {
45
26
  cacheConfig?: CacheConfig;
46
27
  staticGenerate?: boolean;
47
28
  };
@@ -11,4 +11,5 @@ export declare class RouteMatchManager {
11
11
  matchEntry(entryname: string): RouteMatcher | undefined;
12
12
  getBundles(): (string | undefined)[];
13
13
  }
14
- export type { ModernRouteInterface, RouteMatcher, ModernRoute };
14
+ export type { ModernRouteInterface, ModernRoute };
15
+ export { RouteMatcher };
@@ -1,13 +1,5 @@
1
- export interface ModernRouteInterface {
2
- entryName: string;
3
- urlPath: string;
4
- entryPath?: string;
5
- isSPA?: boolean;
6
- isSSR?: boolean;
7
- isApi?: boolean;
8
- bundle?: string;
9
- enableModernMode?: boolean;
10
- }
1
+ import { ServerRoute as ModernRouteInterface } from '@modern-js/types';
2
+ export type { ModernRouteInterface };
11
3
  export declare class ModernRoute implements ModernRouteInterface {
12
4
  entryName: string;
13
5
  urlPath: string;
@@ -2,7 +2,7 @@
2
2
  import { IncomingMessage, ServerResponse, Server } from 'http';
3
3
  import { Adapter, APIServerStartInput } from '@modern-js/server-plugin';
4
4
  import type { NormalizedConfig } from '@modern-js/core';
5
- import { ModernServerOptions, NextFunction, ServerHookRunner, Measure, Logger, ReadyOptions } from "../type.d";
5
+ import { ModernServerOptions, NextFunction, ServerHookRunner, Metrics, Logger, ReadyOptions } from "../type.d";
6
6
  import { RouteMatchManager, ModernRouteInterface, ModernRoute, RouteMatcher } from "../libs/route";
7
7
  import { mergeExtension } from "../utils.d";
8
8
  import { ModernServerContext } from "../libs/context";
@@ -19,16 +19,16 @@ export declare class ModernServer {
19
19
  protected presetRoutes?: ModernRouteInterface[];
20
20
  protected runner: ServerHookRunner;
21
21
  protected readonly logger: Logger;
22
- protected readonly measure: Measure;
22
+ protected readonly metrics: Metrics;
23
23
  protected readonly proxyTarget: ModernServerOptions['proxyTarget'];
24
24
  private readonly isDev;
25
25
  private staticFileHandler;
26
26
  private routeRenderHandler;
27
27
  private frameWebHandler;
28
28
  private frameAPIHandler;
29
+ private proxyHandler;
29
30
  private _handler;
30
31
  private readonly staticGenerate;
31
- private proxyHandler;
32
32
  constructor({
33
33
  pwd,
34
34
  config,
@@ -36,7 +36,7 @@ export declare class ModernServer {
36
36
  routes,
37
37
  staticGenerate,
38
38
  logger,
39
- measure,
39
+ metrics,
40
40
  proxyTarget
41
41
  }: ModernServerOptions);
42
42
  getRequestHandler(): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
@@ -2,8 +2,14 @@
2
2
  import type Webpack from 'webpack';
3
3
  import { serverManager } from '@modern-js/server-plugin';
4
4
  import type { NormalizedConfig } from '@modern-js/core';
5
- import type { Measure, Logger, NextFunction } from '@modern-js/types/server';
5
+ import type { Metrics, Logger, NextFunction } from '@modern-js/types/server';
6
6
  import { ModernRouteInterface } from './libs/route';
7
+ declare module 'http' {
8
+ interface IncomingMessage {
9
+ logger: Logger;
10
+ metrics: Metrics;
11
+ }
12
+ }
7
13
  declare module '@modern-js/core' {
8
14
  interface UserConfig {
9
15
  bff: {
@@ -23,6 +29,7 @@ export declare type DevServerOptions = {
23
29
  dev: {
24
30
  writeToDisk: boolean | ((filename: string) => boolean);
25
31
  };
32
+ watch: boolean;
26
33
  hot: boolean | string;
27
34
  liveReload: boolean;
28
35
  https?: boolean | {
@@ -35,15 +42,15 @@ export declare type ModernServerOptions = {
35
42
  pwd: string;
36
43
  config: NormalizedConfig;
37
44
  plugins?: any[];
38
- dev?: boolean | DevServerOptions;
45
+ dev?: boolean | Partial<DevServerOptions>;
39
46
  compiler?: Webpack.MultiCompiler | Webpack.Compiler;
40
47
  routes?: ModernRouteInterface[];
41
48
  staticGenerate?: boolean;
42
49
  customServer?: boolean;
43
50
  loggerOptions?: Record<string, string>;
44
- measureOptions?: Record<string, string>;
51
+ metricsOptions?: Record<string, string>;
45
52
  logger?: Logger;
46
- measure?: Measure;
53
+ metrics?: Metrics;
47
54
  apiOnly?: boolean;
48
55
  ssrOnly?: boolean;
49
56
  webOnly?: boolean;
@@ -68,4 +75,4 @@ export declare type ServerHookRunner = Then<ReturnType<typeof serverManager.init
68
75
  export declare type ReadyOptions = {
69
76
  routes?: ModernRouteInterface[];
70
77
  };
71
- export type { Measure, Logger, NextFunction };
78
+ export type { Metrics, Logger, NextFunction };
@@ -3,5 +3,4 @@ export declare const mergeExtension: (users: any[]) => {
3
3
  };
4
4
  export declare const toMessage: (dig: string, e: Error | string) => string;
5
5
  export declare const noop: () => void;
6
- export declare const createErrorDocument: (status: number, text: string) => string;
7
- export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
6
+ export declare const createErrorDocument: (status: number, text: string) => string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.4",
14
+ "version": "1.2.1-beta.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -33,12 +33,12 @@
33
33
  "@babel/preset-typescript": "^7.15.0",
34
34
  "@babel/register": "^7.15.3",
35
35
  "@babel/runtime": "^7",
36
- "@modern-js/core": "^1.1.4",
36
+ "@modern-js/core": "^1.2.0",
37
37
  "@modern-js/hmr-client": "^1.1.1",
38
- "@modern-js/server-plugin": "^1.1.2",
38
+ "@modern-js/server-plugin": "^1.1.3",
39
39
  "@modern-js/server-utils": "^1.1.2",
40
40
  "@modern-js/bff-utils": "^1.1.1",
41
- "@modern-js/utils": "^1.1.4",
41
+ "@modern-js/utils": "^1.1.5",
42
42
  "axios": "^0.21.4",
43
43
  "babel-plugin-module-resolver": "^4.1.0",
44
44
  "chokidar": "^3.5.2",
@@ -61,9 +61,9 @@
61
61
  "ws": "^8.2.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@modern-js/module-tools": "^1.1.1",
65
- "@modern-js/plugin-testing": "^1.1.1",
66
- "@modern-js/types": "^1.1.3",
64
+ "@modern-js/module-tools": "^1.1.3",
65
+ "@modern-js/plugin-testing": "^1.2.0",
66
+ "@modern-js/types": "^1.1.4",
67
67
  "@types/jest": "^26",
68
68
  "@types/lru-cache": "^5.1.1",
69
69
  "@types/mime-types": "^2.1.0",
@@ -78,7 +78,9 @@
78
78
  "@types/webpack-dev-middleware": "^5.0.2",
79
79
  "@types/ws": "^7.4.7",
80
80
  "typescript": "^4",
81
- "webpack": "^5.54.0"
81
+ "webpack": "^5.54.0",
82
+ "node-mocks-http": "^1.11.0",
83
+ "portfinder": "^1.0.28"
82
84
  },
83
85
  "peerDependencies": {
84
86
  "webpack": "^5.54.0"
@@ -97,7 +99,7 @@
97
99
  "new": "modern new",
98
100
  "build": "modern build",
99
101
  "dev": "modern build --watch",
100
- "test": "modern test --passWithNoTests"
102
+ "test": "modern test"
101
103
  },
102
104
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
103
105
  }
package/src/index.ts CHANGED
@@ -1,19 +1,13 @@
1
1
  import { ModernServerOptions } from './type';
2
-
3
2
  import { Server } from './server';
4
3
 
5
- export * from './type';
6
- export * from './libs/context';
7
- export * from './libs/route';
8
4
  export type { SSRServerContext } from './libs/render/type';
9
5
  export { Server };
6
+ export type { ModernServerOptions };
10
7
 
11
8
  export default (options: ModernServerOptions): Promise<Server> => {
12
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
- const allowEnvs = ['production', 'development', 'test'];
14
-
15
9
  if (options == null) {
16
- throw new Error();
10
+ throw new Error('can not start mserver without options');
17
11
  }
18
12
 
19
13
  const server = new Server(options);