@modern-js/prod-server 2.32.2-alpha.1 → 2.33.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,13 +1,18 @@
1
1
  # @modern-js/prod-server
2
2
 
3
- ## 2.32.2-alpha.0
3
+ ## 2.33.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [bc1f8daf0ff]
8
- - @modern-js/utils@2.32.2-alpha.0
9
- - @modern-js/server-core@2.32.2-alpha.0
10
- - @modern-js/plugin@2.32.2-alpha.0
7
+ - 1042583: fix(prod-server): set res.statusCode = 200 when routes matches success
8
+ fix(prod-server): 路由匹配成功后 设置 res.statusCode = 200
9
+ - 3ba1682: fix(prod-server): optimize ssr preload
10
+ fix(prod-server): 优化 ssr preload
11
+ - Updated dependencies [fd82137]
12
+ - Updated dependencies [bc1f8da]
13
+ - @modern-js/utils@2.33.0
14
+ - @modern-js/server-core@2.33.0
15
+ - @modern-js/plugin@2.33.0
11
16
 
12
17
  ## 2.32.1
13
18
 
@@ -17,7 +17,7 @@ const _remixrouter = require("@modern-js/utils/runtime/remix-router");
17
17
  const _runtimenode = require("@modern-js/utils/runtime-node");
18
18
  async function parseLinks({ pathname, distDir, template }) {
19
19
  const links = await parseLinksFromRoutes(pathname, distDir);
20
- return links.length > 0 ? links : parseLinksFromHtml(template);
20
+ return links.concat(parseLinksFromHtml(template));
21
21
  }
22
22
  function parseLinksFromHtml(html) {
23
23
  const root = (0, _nodehtmlparser.parse)(html);
@@ -11,10 +11,10 @@ Object.defineProperty(exports, "transformLinks2String", {
11
11
  const _flushServerHeader = require("./flushServerHeader");
12
12
  function transformLinks2String(links, preload) {
13
13
  if (typeof preload === "boolean") {
14
- return links.map(({ uri, as }) => as ? `<${uri}>; rel=preload; as=${as}` : `<${uri}>; rel=preload`).join(", ");
14
+ return dedup(links).map(({ uri, as }) => as ? `<${uri}>; rel=preload; as=${as}` : `<${uri}>; rel=preload`).join(", ");
15
15
  }
16
16
  const { include, exclude, attributes } = preload;
17
- const resolveLinks = addAttributes(removeExclude(addInclude(links, include), exclude), attributes);
17
+ const resolveLinks = addAttributes(dedup(removeExclude(addInclude(links, include), exclude)), attributes);
18
18
  return resolveLinks.join(", ");
19
19
  function addInclude(links2, include2) {
20
20
  var _include;
@@ -110,4 +110,14 @@ function transformLinks2String(links, preload) {
110
110
  return `<${uri}>; rel=preload`;
111
111
  });
112
112
  }
113
+ function dedup(links2) {
114
+ const set = /* @__PURE__ */ new Set();
115
+ return links2.filter(({ uri }) => {
116
+ if (set.has(uri)) {
117
+ return false;
118
+ }
119
+ set.add(uri);
120
+ return true;
121
+ });
122
+ }
113
123
  }
@@ -86,6 +86,7 @@ class ModernServer {
86
86
  if (!matched) {
87
87
  return null;
88
88
  }
89
+ res.statusCode = 200;
89
90
  const route = matched.generate(context.url);
90
91
  const result = await this.handleWeb(context, route);
91
92
  if (!result) {
@@ -24,7 +24,7 @@ function _parseLinks() {
24
24
  links = _state.sent();
25
25
  return [
26
26
  2,
27
- links.length > 0 ? links : parseLinksFromHtml(template)
27
+ links.concat(parseLinksFromHtml(template))
28
28
  ];
29
29
  }
30
30
  });
@@ -106,13 +106,24 @@ export function transformLinks2String(links, preload) {
106
106
  return "<".concat(uri, ">; rel=preload");
107
107
  });
108
108
  };
109
+ var dedup = function dedup2(links2) {
110
+ var set = /* @__PURE__ */ new Set();
111
+ return links2.filter(function(param) {
112
+ var uri = param.uri;
113
+ if (set.has(uri)) {
114
+ return false;
115
+ }
116
+ set.add(uri);
117
+ return true;
118
+ });
119
+ };
109
120
  if (typeof preload === "boolean") {
110
- return links.map(function(param) {
121
+ return dedup(links).map(function(param) {
111
122
  var uri = param.uri, as = param.as;
112
123
  return as ? "<".concat(uri, ">; rel=preload; as=").concat(as) : "<".concat(uri, ">; rel=preload");
113
124
  }).join(", ");
114
125
  }
115
126
  var include = preload.include, exclude = preload.exclude, attributes = preload.attributes;
116
- var resolveLinks = addAttributes(removeExclude(addInclude(links, include), exclude), attributes);
127
+ var resolveLinks = addAttributes(dedup(removeExclude(addInclude(links, include), exclude)), attributes);
117
128
  return resolveLinks.join(", ");
118
129
  }
@@ -176,6 +176,7 @@ export var ModernServer = /* @__PURE__ */ function() {
176
176
  null
177
177
  ];
178
178
  }
179
+ res.statusCode = 200;
179
180
  route = matched.generate(context.url);
180
181
  return [
181
182
  4,
@@ -5,7 +5,7 @@ import { matchRoutes } from "@modern-js/utils/runtime/remix-router";
5
5
  import { matchEntry } from "@modern-js/utils/runtime-node";
6
6
  export async function parseLinks({ pathname, distDir, template }) {
7
7
  const links = await parseLinksFromRoutes(pathname, distDir);
8
- return links.length > 0 ? links : parseLinksFromHtml(template);
8
+ return links.concat(parseLinksFromHtml(template));
9
9
  }
10
10
  function parseLinksFromHtml(html) {
11
11
  const root = htmlParse(html);
@@ -1,10 +1,10 @@
1
1
  import { transformToRegExp } from "./flushServerHeader";
2
2
  export function transformLinks2String(links, preload) {
3
3
  if (typeof preload === "boolean") {
4
- return links.map(({ uri, as }) => as ? `<${uri}>; rel=preload; as=${as}` : `<${uri}>; rel=preload`).join(", ");
4
+ return dedup(links).map(({ uri, as }) => as ? `<${uri}>; rel=preload; as=${as}` : `<${uri}>; rel=preload`).join(", ");
5
5
  }
6
6
  const { include, exclude, attributes } = preload;
7
- const resolveLinks = addAttributes(removeExclude(addInclude(links, include), exclude), attributes);
7
+ const resolveLinks = addAttributes(dedup(removeExclude(addInclude(links, include), exclude)), attributes);
8
8
  return resolveLinks.join(", ");
9
9
  function addInclude(links2, include2) {
10
10
  var _include;
@@ -100,4 +100,14 @@ export function transformLinks2String(links, preload) {
100
100
  return `<${uri}>; rel=preload`;
101
101
  });
102
102
  }
103
+ function dedup(links2) {
104
+ const set = /* @__PURE__ */ new Set();
105
+ return links2.filter(({ uri }) => {
106
+ if (set.has(uri)) {
107
+ return false;
108
+ }
109
+ set.add(uri);
110
+ return true;
111
+ });
112
+ }
103
113
  }
@@ -74,6 +74,7 @@ export class ModernServer {
74
74
  if (!matched) {
75
75
  return null;
76
76
  }
77
+ res.statusCode = 200;
77
78
  const route = matched.generate(context.url);
78
79
  const result = await this.handleWeb(context, route);
79
80
  if (!result) {
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
4
  /// <reference types="node/http" />
5
- /// <reference types=".dts-temp/yEtXcyFXobiISlvWle5iM/src/type" />
5
+ /// <reference types=".dts-temp/C8PtmgKJWh8V5V1ezLBNG/src/type" />
6
6
  import { IncomingMessage, ServerResponse } from 'http';
7
7
  import qs from 'querystring';
8
8
  import type { ModernServerContext as ModernServerContextInterface, Reporter as ModernServerReporter, ServerTiming as ModernServerTiming } from '@modern-js/types';
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node/http" />
3
- /// <reference types=".dts-temp/yEtXcyFXobiISlvWle5iM/src/type" />
3
+ /// <reference types=".dts-temp/C8PtmgKJWh8V5V1ezLBNG/src/type" />
4
4
  import { IncomingMessage } from 'http';
5
5
  import type { OutputNormalizedConfig, HtmlNormalizedConfig } from '@modern-js/server-core';
6
6
  export declare const debug: any;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.32.2-alpha.1",
18
+ "version": "2.33.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -74,9 +74,9 @@
74
74
  "node-html-parser": "^6.1.5",
75
75
  "path-to-regexp": "^6.2.0",
76
76
  "serve-static": "^1.14.1",
77
- "@modern-js/plugin": "2.32.2-alpha.1",
78
- "@modern-js/utils": "2.32.2-alpha.1",
79
- "@modern-js/server-core": "2.32.2-alpha.1"
77
+ "@modern-js/plugin": "2.33.0",
78
+ "@modern-js/server-core": "2.33.0",
79
+ "@modern-js/utils": "2.33.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@types/cookie": "^0.4.1",
@@ -95,10 +95,10 @@
95
95
  "portfinder": "^1.0.28",
96
96
  "typescript": "^5",
97
97
  "ws": "^8.13.0",
98
- "@modern-js/server-core": "2.32.2-alpha.1",
99
- "@modern-js/types": "2.32.2-alpha.1",
100
- "@scripts/build": "2.32.1",
101
- "@scripts/jest-config": "2.32.1"
98
+ "@modern-js/server-core": "2.33.0",
99
+ "@modern-js/types": "2.33.0",
100
+ "@scripts/build": "2.33.0",
101
+ "@scripts/jest-config": "2.33.0"
102
102
  },
103
103
  "sideEffects": false,
104
104
  "publishConfig": {