@modern-js/prod-server 2.0.0-beta.0 → 2.0.0-beta.1

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 (113) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/js/modern/constants.js +0 -2
  3. package/dist/js/modern/index.js +0 -1
  4. package/dist/js/modern/libs/context/context.js +10 -56
  5. package/dist/js/modern/libs/hook-api/index.js +0 -31
  6. package/dist/js/modern/libs/hook-api/route.js +0 -8
  7. package/dist/js/modern/libs/hook-api/template.js +0 -16
  8. package/dist/js/modern/libs/loadConfig.js +3 -10
  9. package/dist/js/modern/libs/metrics.js +6 -6
  10. package/dist/js/modern/libs/proxy.js +7 -12
  11. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -1
  12. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -9
  13. package/dist/js/modern/libs/render/cache/index.js +8 -16
  14. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -10
  15. package/dist/js/modern/libs/render/cache/spr.js +12 -62
  16. package/dist/js/modern/libs/render/cache/util.js +0 -6
  17. package/dist/js/modern/libs/render/index.js +6 -11
  18. package/dist/js/modern/libs/render/measure.js +1 -11
  19. package/dist/js/modern/libs/render/modern/index.js +2 -13
  20. package/dist/js/modern/libs/render/reader.js +13 -24
  21. package/dist/js/modern/libs/render/ssr.js +5 -6
  22. package/dist/js/modern/libs/render/static.js +6 -9
  23. package/dist/js/modern/libs/render/type.js +0 -1
  24. package/dist/js/modern/libs/route/index.js +8 -19
  25. package/dist/js/modern/libs/route/matcher.js +21 -29
  26. package/dist/js/modern/libs/route/route.js +0 -13
  27. package/dist/js/modern/libs/serve-file.js +5 -6
  28. package/dist/js/modern/server/index.js +19 -41
  29. package/dist/js/modern/server/modern-server-split.js +0 -11
  30. package/dist/js/modern/server/modern-server.js +83 -164
  31. package/dist/js/modern/utils.js +2 -21
  32. package/dist/js/modern/worker-server.js +34 -0
  33. package/dist/js/node/constants.js +0 -2
  34. package/dist/js/node/index.js +0 -10
  35. package/dist/js/node/libs/context/context.js +10 -65
  36. package/dist/js/node/libs/context/index.js +0 -3
  37. package/dist/js/node/libs/hook-api/index.js +0 -42
  38. package/dist/js/node/libs/hook-api/route.js +0 -10
  39. package/dist/js/node/libs/hook-api/template.js +0 -22
  40. package/dist/js/node/libs/loadConfig.js +3 -22
  41. package/dist/js/node/libs/metrics.js +6 -6
  42. package/dist/js/node/libs/proxy.js +7 -17
  43. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -5
  44. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -12
  45. package/dist/js/node/libs/render/cache/index.js +8 -22
  46. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -2
  47. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -14
  48. package/dist/js/node/libs/render/cache/spr.js +12 -71
  49. package/dist/js/node/libs/render/cache/util.js +0 -18
  50. package/dist/js/node/libs/render/index.js +6 -26
  51. package/dist/js/node/libs/render/measure.js +0 -17
  52. package/dist/js/node/libs/render/modern/index.js +2 -20
  53. package/dist/js/node/libs/render/reader.js +12 -39
  54. package/dist/js/node/libs/render/ssr.js +4 -16
  55. package/dist/js/node/libs/render/static.js +6 -18
  56. package/dist/js/node/libs/render/type.js +0 -1
  57. package/dist/js/node/libs/route/index.js +8 -22
  58. package/dist/js/node/libs/route/matcher.js +18 -34
  59. package/dist/js/node/libs/route/route.js +0 -15
  60. package/dist/js/node/libs/serve-file.js +5 -13
  61. package/dist/js/node/server/index.js +19 -61
  62. package/dist/js/node/server/modern-server-split.js +0 -13
  63. package/dist/js/node/server/modern-server.js +83 -193
  64. package/dist/js/node/utils.js +3 -46
  65. package/dist/js/node/worker-server.js +41 -0
  66. package/dist/js/treeshaking/constants.js +28 -0
  67. package/dist/js/treeshaking/index.js +13 -0
  68. package/dist/js/treeshaking/libs/context/context.js +243 -0
  69. package/dist/js/treeshaking/libs/context/index.js +5 -0
  70. package/dist/js/treeshaking/libs/hook-api/index.js +157 -0
  71. package/dist/js/treeshaking/libs/hook-api/route.js +33 -0
  72. package/dist/js/treeshaking/libs/hook-api/template.js +91 -0
  73. package/dist/js/treeshaking/libs/loadConfig.js +39 -0
  74. package/dist/js/treeshaking/libs/metrics.js +12 -0
  75. package/dist/js/treeshaking/libs/proxy.js +80 -0
  76. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +124 -0
  77. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +464 -0
  78. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +53 -0
  79. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +35 -0
  80. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +121 -0
  81. package/dist/js/treeshaking/libs/render/cache/index.js +184 -0
  82. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +30 -0
  83. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +46 -0
  84. package/dist/js/treeshaking/libs/render/cache/spr.js +362 -0
  85. package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
  86. package/dist/js/treeshaking/libs/render/cache/util.js +101 -0
  87. package/dist/js/treeshaking/libs/render/index.js +100 -0
  88. package/dist/js/treeshaking/libs/render/measure.js +61 -0
  89. package/dist/js/treeshaking/libs/render/modern/browser-list.js +7 -0
  90. package/dist/js/treeshaking/libs/render/modern/index.js +39 -0
  91. package/dist/js/treeshaking/libs/render/reader.js +191 -0
  92. package/dist/js/treeshaking/libs/render/ssr.js +98 -0
  93. package/dist/js/treeshaking/libs/render/static.js +84 -0
  94. package/dist/js/treeshaking/libs/render/type.js +6 -0
  95. package/dist/js/treeshaking/libs/route/index.js +94 -0
  96. package/dist/js/treeshaking/libs/route/matcher.js +113 -0
  97. package/dist/js/treeshaking/libs/route/route.js +26 -0
  98. package/dist/js/treeshaking/libs/serve-file.js +75 -0
  99. package/dist/js/treeshaking/server/index.js +343 -0
  100. package/dist/js/treeshaking/server/modern-server-split.js +152 -0
  101. package/dist/js/treeshaking/server/modern-server.js +945 -0
  102. package/dist/js/treeshaking/type.js +1 -0
  103. package/dist/js/treeshaking/utils.js +87 -0
  104. package/dist/js/treeshaking/worker-server.js +56 -0
  105. package/dist/types/index.d.ts +0 -2
  106. package/dist/types/libs/context/context.d.ts +0 -3
  107. package/dist/types/libs/loadConfig.d.ts +0 -1
  108. package/dist/types/libs/render/cache/index.d.ts +0 -2
  109. package/dist/types/libs/render/cache/spr.d.ts +0 -2
  110. package/dist/types/server/index.d.ts +0 -3
  111. package/dist/types/utils.d.ts +0 -1
  112. package/dist/types/worker-server.d.ts +16 -0
  113. package/package.json +28 -12
@@ -1,13 +1,10 @@
1
1
  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; }
2
-
3
2
  import { fs } from '@modern-js/utils';
4
3
  import LRU from 'lru-cache';
5
4
  const Byte = 1;
6
5
  const KB = 1024 * Byte;
7
6
  const MB = 1024 * KB;
8
-
9
7
  const getContentLength = cache => cache.content.length;
10
-
11
8
  const createCacheItem = async (filepath, mtime) => {
12
9
  const content = await fs.readFile(filepath);
13
10
  return {
@@ -15,28 +12,26 @@ const createCacheItem = async (filepath, mtime) => {
15
12
  mtime
16
13
  };
17
14
  };
18
-
19
15
  export class LruReader {
20
16
  // private timer?: NodeJS.Timeout;
17
+
21
18
  constructor() {
22
19
  _defineProperty(this, "cache", void 0);
23
-
24
20
  this.cache = new LRU({
25
21
  max: 256 * MB,
26
22
  length: getContentLength,
27
23
  maxAge: 5 * 60 * 5000 // 60s
28
-
29
24
  });
30
25
  }
31
26
 
32
- init() {// this.timeTask();
27
+ init() {
28
+ // this.timeTask();
33
29
  }
34
-
35
- close() {// if (this.timer) {
30
+ close() {
31
+ // if (this.timer) {
36
32
  // clearInterval(this.timer);
37
33
  // }
38
34
  }
39
-
40
35
  async read(filepath) {
41
36
  if (this.cache.has(filepath)) {
42
37
  const {
@@ -46,45 +41,38 @@ export class LruReader {
46
41
  content
47
42
  };
48
43
  }
49
-
50
44
  if (!fs.existsSync(filepath)) {
51
45
  return null;
52
46
  }
53
-
54
47
  const stat = fs.statSync(filepath);
55
-
56
48
  if (stat.isDirectory()) {
57
49
  return null;
58
- } // if file more than 20 MB
59
-
50
+ }
60
51
 
52
+ // if file more than 20 MB
61
53
  if (stat.size > 20 * MB) {
62
54
  return null;
63
55
  }
64
-
65
56
  const item = await createCacheItem(filepath, stat.mtime);
66
57
  this.cache.set(filepath, item);
67
58
  return item;
68
59
  }
69
-
70
60
  update() {
71
61
  const {
72
62
  cache
73
63
  } = this;
74
64
  const files = cache.keys();
75
-
76
65
  for (const filepath of files) {
77
66
  if (!fs.existsSync(filepath)) {
78
67
  cache.del(filepath);
79
68
  }
80
-
81
69
  try {
82
70
  const item = cache.get(filepath);
83
71
  const stat = fs.statSync(filepath);
84
72
  const {
85
73
  mtime
86
- } = stat; // file is modify
87
-
74
+ } = stat;
75
+ // file is modify
88
76
  if (item.mtime < mtime) {
89
77
  cache.del(filepath);
90
78
  }
@@ -93,12 +81,13 @@ export class LruReader {
93
81
  cache.del(filepath);
94
82
  }
95
83
  }
96
- } // private timeTask() {
84
+ }
85
+
86
+ // private timeTask() {
97
87
  // this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
98
88
  // }
99
-
100
-
101
89
  }
90
+
102
91
  const reader = new LruReader();
103
92
  export const readFile = async filepath => {
104
93
  const file = await reader.read(filepath);
@@ -1,11 +1,10 @@
1
1
  import path from 'path';
2
- import { fs, LOADABLE_STATS_FILE, mime, SERVER_RENDER_FUNCTION_NAME } from '@modern-js/utils';
2
+ import { fs, LOADABLE_STATS_FILE, mime, ROUTE_MINIFEST_FILE, SERVER_RENDER_FUNCTION_NAME } from '@modern-js/utils';
3
3
  import cookie from 'cookie';
4
4
  import cache from "./cache";
5
5
  import { createLogger, createMetrics } from "./measure";
6
6
  export const render = async (ctx, renderOptions, runner) => {
7
7
  var _ctx$res;
8
-
9
8
  const {
10
9
  urlPath,
11
10
  bundle,
@@ -17,6 +16,8 @@ export const render = async (ctx, renderOptions, runner) => {
17
16
  const bundleJS = path.join(distDir, bundle);
18
17
  const loadableUri = path.join(distDir, LOADABLE_STATS_FILE);
19
18
  const loadableStats = fs.existsSync(loadableUri) ? require(loadableUri) : '';
19
+ const routesManifestUri = path.join(distDir, ROUTE_MINIFEST_FILE);
20
+ const routeManifest = fs.existsSync(routesManifestUri) ? require(routesManifestUri) : undefined;
20
21
  const context = {
21
22
  request: {
22
23
  baseUrl: urlPath,
@@ -40,6 +41,8 @@ export const render = async (ctx, renderOptions, runner) => {
40
41
  redirection: {},
41
42
  template,
42
43
  loadableStats,
44
+ routeManifest,
45
+ // for streaming ssr
43
46
  entryName,
44
47
  staticGenerate,
45
48
  logger: undefined,
@@ -50,15 +53,12 @@ export const render = async (ctx, renderOptions, runner) => {
50
53
  context.logger = createLogger(context, ctx.logger);
51
54
  context.metrics = createMetrics(context, ctx.metrics);
52
55
  runner.extendSSRContext(context);
53
-
54
56
  const serverRender = require(bundleJS)[SERVER_RENDER_FUNCTION_NAME];
55
-
56
57
  const content = await cache(serverRender, ctx)(context);
57
58
  const {
58
59
  url,
59
60
  status = 302
60
61
  } = context.redirection;
61
-
62
62
  if (url) {
63
63
  return {
64
64
  content: url,
@@ -67,7 +67,6 @@ export const render = async (ctx, renderOptions, runner) => {
67
67
  redirect: true
68
68
  };
69
69
  }
70
-
71
70
  if (typeof content === 'string') {
72
71
  return {
73
72
  content,
@@ -5,42 +5,39 @@ export async function handleDirectory(ctx, entryPath, urlPath) {
5
5
  const {
6
6
  path: pathname
7
7
  } = ctx;
8
- const filepath = path.join(entryPath, trimLeft(pathname, urlPath)); // If can match accurately, always return the one that matches accurately
8
+ const filepath = path.join(entryPath, trimLeft(pathname, urlPath));
9
9
 
10
+ // If can match accurately, always return the one that matches accurately
10
11
  let content = await readFile(filepath);
11
- let contentType = mime.contentType(path.extname(filepath) || ''); // automatic addressing
12
+ let contentType = mime.contentType(path.extname(filepath) || '');
12
13
 
14
+ // automatic addressing
13
15
  if (!content) {
14
16
  if (pathname.endsWith('/')) {
15
17
  content = await readFile(`${filepath}index.html`);
16
18
  } else if (!pathname.includes('.')) {
17
19
  content = await readFile(`${filepath}.html`);
18
-
19
20
  if (!content) {
20
21
  content = await readFile(`${filepath}/index.html`);
21
22
  }
22
- } // set content-type as html
23
-
23
+ }
24
24
 
25
+ // set content-type as html
25
26
  if (content) {
26
27
  contentType = mime.contentType('html');
27
28
  }
28
29
  }
29
-
30
30
  if (!content) {
31
31
  return null;
32
32
  }
33
-
34
33
  return {
35
34
  content,
36
35
  contentType: contentType || ''
37
36
  };
38
37
  }
39
-
40
38
  const trimLeft = (str, prefix) => {
41
39
  if (str.startsWith(prefix)) {
42
40
  return str.substring(prefix.length);
43
41
  }
44
-
45
42
  return str;
46
43
  };
@@ -1,5 +1,4 @@
1
1
  export let RenderLevel;
2
-
3
2
  (function (RenderLevel) {
4
3
  RenderLevel[RenderLevel["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
5
4
  RenderLevel[RenderLevel["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
@@ -1,48 +1,40 @@
1
1
  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; }
2
-
3
2
  import { RouteMatcher } from "./matcher";
4
3
  export class RouteMatchManager {
5
4
  constructor() {
6
5
  _defineProperty(this, "matchers", void 0);
7
-
8
6
  _defineProperty(this, "specs", []);
9
-
10
7
  this.matchers = [];
11
- } // get all routes matches pathname
12
-
8
+ }
13
9
 
10
+ // get all routes matches pathname
14
11
  filter(pathname) {
15
12
  return this.matchers.reduce((matches, matcher) => {
16
13
  if (matcher.matchUrlPath(pathname)) {
17
14
  matches.push(matcher);
18
15
  }
19
-
20
16
  return matches;
21
17
  }, []);
22
- } // get best match from a set of matches
23
-
18
+ }
24
19
 
20
+ // get best match from a set of matches
25
21
  best(pathname, matches) {
26
22
  let best;
27
23
  let matchedLen = 0;
28
-
29
24
  for (const match of matches) {
30
25
  const len = match.matchLength(pathname);
31
-
32
26
  if (len === null) {
33
27
  continue;
34
28
  }
35
-
36
29
  if (len > matchedLen) {
37
30
  best = match;
38
31
  matchedLen = len;
39
32
  }
40
33
  }
41
-
42
34
  return best;
43
- } // reset routes matcher
44
-
35
+ }
45
36
 
37
+ // reset routes matcher
46
38
  reset(specs) {
47
39
  this.specs = specs;
48
40
  const matchers = specs.reduce((ms, spec) => {
@@ -50,23 +42,20 @@ export class RouteMatchManager {
50
42
  return ms;
51
43
  }, []);
52
44
  this.matchers = matchers;
53
- } // get best match from all matcher in manager
54
-
45
+ }
55
46
 
47
+ // get best match from all matcher in manager
56
48
  match(pathname) {
57
49
  const matches = this.filter(pathname);
58
50
  const best = this.best(pathname, matches);
59
51
  return best;
60
52
  }
61
-
62
53
  matchEntry(entryname) {
63
54
  return this.matchers.find(matcher => matcher.matchEntry(entryname));
64
55
  }
65
-
66
56
  getBundles() {
67
57
  const bundles = this.specs.filter(route => route.isSSR).map(route => route.bundle);
68
58
  return bundles;
69
59
  }
70
-
71
60
  }
72
61
  export { RouteMatcher };
@@ -1,38 +1,38 @@
1
1
  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; }
2
-
3
- import { removeTailSlash } from '@modern-js/utils';
4
- import { match, pathToRegexp } from 'path-to-regexp';
5
- import { toPath } from "../../utils";
6
- import { ModernRoute } from "./route"; // eslint-disable-next-line no-useless-escape
7
-
2
+ import { match, pathToRegexp, compile } from 'path-to-regexp';
3
+ import { ModernRoute } from "./route";
4
+
5
+ // avoid import @modern-js/utils
6
+ const removeTailSlash = s => s.replace(/\/+$/, '');
7
+ const toPath = (reg, params) => {
8
+ const fn = compile(reg, {
9
+ encode: encodeURIComponent
10
+ });
11
+ return fn(params);
12
+ };
13
+
14
+ // eslint-disable-next-line no-useless-escape
8
15
  const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
9
16
  export class RouteMatcher {
10
17
  constructor(spec) {
11
18
  _defineProperty(this, "spec", void 0);
12
-
13
19
  _defineProperty(this, "urlPath", '');
14
-
15
20
  _defineProperty(this, "urlMatcher", void 0);
16
-
17
21
  _defineProperty(this, "urlReg", void 0);
18
-
19
22
  this.spec = spec;
20
23
  this.setupUrlPath();
21
- } // generate modern route object
22
-
24
+ }
23
25
 
26
+ // generate modern route object
24
27
  generate(url) {
25
28
  const route = new ModernRoute(this.spec);
26
-
27
29
  if (this.urlPath) {
28
30
  const params = this.parseURLParams(url);
29
31
  route.urlPath = toPath(route.urlPath, params);
30
32
  route.params = params;
31
33
  }
32
-
33
34
  return route;
34
35
  }
35
-
36
36
  parseURLParams(pathname) {
37
37
  if (!this.urlMatcher) {
38
38
  return {};
@@ -40,28 +40,25 @@ export class RouteMatcher {
40
40
  const matchResult = this.urlMatcher(pathname);
41
41
  return matchResult.params;
42
42
  }
43
- } // get match url length
44
-
43
+ }
45
44
 
45
+ // get match url length
46
46
  matchLength(pathname) {
47
47
  if (!this.urlReg) {
48
48
  return this.urlPath.length;
49
49
  } else {
50
50
  var _result$;
51
-
52
51
  const result = this.urlReg.exec(pathname);
53
52
  return (result === null || result === void 0 ? void 0 : (_result$ = result[0]) === null || _result$ === void 0 ? void 0 : _result$.length) || null;
54
53
  }
55
- } // if match url path
56
-
54
+ }
57
55
 
56
+ // if match url path
58
57
  matchUrlPath(requestUrl) {
59
58
  let urlWithoutSlash = requestUrl.endsWith('/') && requestUrl !== '/' ? requestUrl.slice(0, -1) : requestUrl;
60
-
61
59
  if (urlWithoutSlash.endsWith('.html')) {
62
60
  urlWithoutSlash = urlWithoutSlash.slice(0, -5);
63
61
  }
64
-
65
62
  if (this.urlMatcher) {
66
63
  return Boolean(this.urlMatcher(urlWithoutSlash));
67
64
  } else {
@@ -70,26 +67,22 @@ export class RouteMatcher {
70
67
  if (this.urlPath !== '/' && urlWithoutSlash.length > this.urlPath.length && !urlWithoutSlash.startsWith(`${this.urlPath}/`)) {
71
68
  return false;
72
69
  }
73
-
74
70
  return true;
75
71
  }
76
-
77
72
  return false;
78
73
  }
79
74
  }
80
-
81
75
  matchEntry(entryName) {
82
76
  return this.spec.entryName === entryName;
83
- } // compiler urlPath to regexp if necessary
84
-
77
+ }
85
78
 
79
+ // compiler urlPath to regexp if necessary
86
80
  setupUrlPath() {
87
81
  const {
88
82
  urlPath
89
83
  } = this.spec;
90
84
  this.urlPath = urlPath === '/' ? urlPath : removeTailSlash(urlPath);
91
85
  const useReg = regCharsDetector.test(urlPath);
92
-
93
86
  if (useReg) {
94
87
  this.urlMatcher = match(urlPath, {
95
88
  end: false,
@@ -100,5 +93,4 @@ export class RouteMatcher {
100
93
  });
101
94
  }
102
95
  }
103
-
104
96
  }
@@ -1,29 +1,17 @@
1
1
  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; }
2
-
3
2
  export class ModernRoute {
4
3
  constructor(routeSpec) {
5
4
  var _routeSpec$enableMode;
6
-
7
5
  _defineProperty(this, "entryName", void 0);
8
-
9
6
  _defineProperty(this, "urlPath", void 0);
10
-
11
7
  _defineProperty(this, "entryPath", void 0);
12
-
13
8
  _defineProperty(this, "bundle", void 0);
14
-
15
9
  _defineProperty(this, "isApi", void 0);
16
-
17
10
  _defineProperty(this, "isSSR", void 0);
18
-
19
11
  _defineProperty(this, "isSPA", void 0);
20
-
21
12
  _defineProperty(this, "enableModernMode", void 0);
22
-
23
13
  _defineProperty(this, "params", {});
24
-
25
14
  _defineProperty(this, "responseHeaders", void 0);
26
-
27
15
  this.entryName = routeSpec.entryName || '';
28
16
  this.urlPath = routeSpec.urlPath;
29
17
  this.entryPath = routeSpec.entryPath || '';
@@ -34,5 +22,4 @@ export class ModernRoute {
34
22
  this.enableModernMode = (_routeSpec$enableMode = routeSpec.enableModernMode) !== null && _routeSpec$enableMode !== void 0 ? _routeSpec$enableMode : false;
35
23
  this.responseHeaders = routeSpec.responseHeaders;
36
24
  }
37
-
38
25
  }
@@ -1,8 +1,8 @@
1
1
  // Todo 看看是不是能 fork 一份,即使命中也返回
2
+
2
3
  import serve from 'serve-static';
3
4
  import { isString, isRegExp } from '@modern-js/utils';
4
5
  import { useLocalPrefix } from "../utils";
5
-
6
6
  const removedPrefix = (req, prefix) => {
7
7
  if (useLocalPrefix(prefix)) {
8
8
  req.url = req.url.slice(prefix.length);
@@ -10,11 +10,11 @@ const removedPrefix = (req, prefix) => {
10
10
  req.url = prefix + req.url;
11
11
  };
12
12
  } else {
13
- return () => {// emptyy
13
+ return () => {
14
+ // emptyy
14
15
  };
15
16
  }
16
17
  };
17
-
18
18
  export const faviconFallbackHandler = (context, next) => {
19
19
  if (context.url === '/favicon.ico') {
20
20
  context.res.statusCode = 204;
@@ -23,7 +23,8 @@ export const faviconFallbackHandler = (context, next) => {
23
23
  next();
24
24
  }
25
25
  };
26
- export const createStaticFileHandler = (rules, output = {}) => // eslint-disable-next-line consistent-return
26
+ export const createStaticFileHandler = (rules, output = {}) =>
27
+ // eslint-disable-next-line consistent-return
27
28
  async (context, next) => {
28
29
  const {
29
30
  url: requestUrl,
@@ -39,10 +40,8 @@ async (context, next) => {
39
40
  } else if (isRegExp(item.path) && item.path.test(requestUrl)) {
40
41
  return true;
41
42
  }
42
-
43
43
  return false;
44
44
  });
45
-
46
45
  if (hitRule) {
47
46
  const resume = removedPrefix(req, assetPrefix);
48
47
  serve(hitRule.target)(req, res, () => {