@modern-js/prod-server 2.47.1 → 2.48.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 (56) hide show
  1. package/dist/cjs/libs/context/context.js +4 -8
  2. package/dist/cjs/libs/hook-api/base.js +0 -11
  3. package/dist/cjs/libs/hook-api/index.worker.js +0 -3
  4. package/dist/cjs/libs/hook-api/route.js +0 -4
  5. package/dist/cjs/libs/hook-api/template.js +0 -2
  6. package/dist/cjs/libs/render/ssr.js +7 -3
  7. package/dist/cjs/libs/render/ssrCache/cacheMod.js +0 -5
  8. package/dist/cjs/libs/render/ssrCache/index.js +10 -3
  9. package/dist/cjs/libs/render/ssrCache/manager.js +25 -11
  10. package/dist/cjs/libs/route/index.js +1 -3
  11. package/dist/cjs/libs/route/matcher.js +1 -5
  12. package/dist/cjs/libs/route/route.js +1 -10
  13. package/dist/cjs/libs/serverTiming.js +0 -3
  14. package/dist/cjs/renderHtml.js +0 -7
  15. package/dist/cjs/server/index.js +1 -7
  16. package/dist/cjs/server/modernServer.js +11 -21
  17. package/dist/cjs/workerServer.js +4 -8
  18. package/dist/esm/libs/context/context.js +66 -98
  19. package/dist/esm/libs/hook-api/base.js +36 -71
  20. package/dist/esm/libs/hook-api/index.worker.js +15 -29
  21. package/dist/esm/libs/hook-api/route.js +12 -27
  22. package/dist/esm/libs/hook-api/template.js +33 -61
  23. package/dist/esm/libs/render/ssr.js +8 -4
  24. package/dist/esm/libs/render/ssrCache/cacheMod.js +10 -18
  25. package/dist/esm/libs/render/ssrCache/index.js +40 -21
  26. package/dist/esm/libs/render/ssrCache/manager.js +149 -141
  27. package/dist/esm/libs/route/index.js +62 -96
  28. package/dist/esm/libs/route/matcher.js +58 -94
  29. package/dist/esm/libs/route/route.js +1 -10
  30. package/dist/esm/libs/serverTiming.js +8 -16
  31. package/dist/esm/renderHtml.js +22 -39
  32. package/dist/esm/server/index.js +307 -383
  33. package/dist/esm/server/modernServer.js +802 -936
  34. package/dist/esm/server/modernServerSplit.js +61 -86
  35. package/dist/esm/workerServer.js +87 -82
  36. package/dist/esm-node/libs/context/context.js +4 -8
  37. package/dist/esm-node/libs/hook-api/base.js +0 -11
  38. package/dist/esm-node/libs/hook-api/index.worker.js +0 -3
  39. package/dist/esm-node/libs/hook-api/route.js +0 -4
  40. package/dist/esm-node/libs/hook-api/template.js +0 -2
  41. package/dist/esm-node/libs/render/ssr.js +7 -3
  42. package/dist/esm-node/libs/render/ssrCache/cacheMod.js +0 -5
  43. package/dist/esm-node/libs/render/ssrCache/index.js +10 -3
  44. package/dist/esm-node/libs/render/ssrCache/manager.js +25 -11
  45. package/dist/esm-node/libs/route/index.js +1 -3
  46. package/dist/esm-node/libs/route/matcher.js +1 -5
  47. package/dist/esm-node/libs/route/route.js +1 -10
  48. package/dist/esm-node/libs/serverTiming.js +0 -3
  49. package/dist/esm-node/renderHtml.js +0 -7
  50. package/dist/esm-node/server/index.js +1 -7
  51. package/dist/esm-node/server/modernServer.js +11 -21
  52. package/dist/esm-node/workerServer.js +4 -8
  53. package/dist/types/libs/render/ssrCache/index.d.ts +2 -3
  54. package/dist/types/libs/render/ssrCache/manager.d.ts +7 -1
  55. package/dist/types/type.d.ts +1 -0
  56. package/package.json +8 -8
@@ -3,7 +3,6 @@ import { _ as _class_private_field_get } from "@swc/helpers/_/_class_private_fie
3
3
  import { _ as _class_private_field_init } from "@swc/helpers/_/_class_private_field_init";
4
4
  import { _ as _class_private_field_set } from "@swc/helpers/_/_class_private_field_set";
5
5
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
6
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
7
6
  import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
8
7
  import { URL } from "url";
9
8
  import qs from "querystring";
@@ -20,13 +19,6 @@ var ModernServerContext = /* @__PURE__ */ function() {
20
19
  "use strict";
21
20
  function ModernServerContext2(req, res, options) {
22
21
  _class_call_check(this, ModernServerContext2);
23
- _define_property(this, "req", void 0);
24
- _define_property(this, "res", void 0);
25
- _define_property(this, "params", {});
26
- _define_property(this, "reporter", defaultReporter);
27
- _define_property(this, "serverTiming", void 0);
28
- _define_property(this, "serverData", {});
29
- _define_property(this, "options", {});
30
22
  _class_private_field_init(this, _urls, {
31
23
  writable: true,
32
24
  value: void 0
@@ -35,6 +27,10 @@ var ModernServerContext = /* @__PURE__ */ function() {
35
27
  writable: true,
36
28
  value: void 0
37
29
  });
30
+ this.params = {};
31
+ this.reporter = defaultReporter;
32
+ this.serverData = {};
33
+ this.options = {};
38
34
  this.req = req;
39
35
  this.res = res;
40
36
  this.options = options || {};
@@ -44,6 +40,68 @@ var ModernServerContext = /* @__PURE__ */ function() {
44
40
  this.serverTiming = new ServerTiming(this.res, cutNameByHyphen((options === null || options === void 0 ? void 0 : options.metaName) || "modern-js"));
45
41
  req.reporter && (this.reporter = req.reporter);
46
42
  }
43
+ var _proto = ModernServerContext2.prototype;
44
+ _proto.bind = function bind() {
45
+ var _this = this;
46
+ var _this1 = this, req = _this1.req, res = _this1.res;
47
+ req.get = function(key) {
48
+ return _this.getReqHeader(key);
49
+ };
50
+ res.set = function(key, value) {
51
+ if (!res.headersSent) {
52
+ res.setHeader(key, value);
53
+ }
54
+ return res;
55
+ };
56
+ res.send = function(body) {
57
+ _this.send(body);
58
+ };
59
+ };
60
+ _proto.send = function send(body) {
61
+ try {
62
+ var generateETag = !this.res.getHeader("ETag") && this.options.etag;
63
+ if (body !== void 0 && generateETag) {
64
+ var encoding = typeof body === "string" ? "utf-8" : void 0;
65
+ var buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
66
+ var etag = createEtag(buf, {
67
+ weak: true
68
+ });
69
+ if (etag) {
70
+ this.res.setHeader("ETag", etag);
71
+ }
72
+ }
73
+ if (this.fresh) {
74
+ this.status = 304;
75
+ }
76
+ } catch (e) {
77
+ this.logger.error(e.message);
78
+ }
79
+ this.res.end(body);
80
+ };
81
+ _proto.setParams = function setParams(params) {
82
+ this.params = params;
83
+ };
84
+ _proto.setServerData = function setServerData(key, value) {
85
+ this.serverData[key] = value;
86
+ };
87
+ _proto.getReqHeader = function getReqHeader(key) {
88
+ var req = this.req;
89
+ var field = key.toLowerCase();
90
+ switch (field) {
91
+ case "referer":
92
+ case "referrer":
93
+ return req.headers.referrer || req.headers.referer || "";
94
+ default:
95
+ return req.headers[field] || "";
96
+ }
97
+ };
98
+ _proto.resHasHandled = function resHasHandled() {
99
+ return this.res.writableEnded;
100
+ };
101
+ _proto.error = function error(dig) {
102
+ var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
103
+ this.logger.error("Web Server Error - ".concat(dig, ", error = %s, req.url = %s, req.headers = %o"), _instanceof(e, Error) ? e.stack || e.message : e, this.path, headersWithoutCookie(this.headers));
104
+ };
47
105
  _create_class(ModernServerContext2, [
48
106
  {
49
107
  key: "logger",
@@ -73,78 +131,6 @@ var ModernServerContext = /* @__PURE__ */ function() {
73
131
  }
74
132
  }
75
133
  },
76
- {
77
- key: "bind",
78
- value: function bind() {
79
- var _this = this;
80
- var _this1 = this, req = _this1.req, res = _this1.res;
81
- req.get = function(key) {
82
- return _this.getReqHeader(key);
83
- };
84
- res.set = function(key, value) {
85
- if (!res.headersSent) {
86
- res.setHeader(key, value);
87
- }
88
- return res;
89
- };
90
- res.send = function(body) {
91
- _this.send(body);
92
- };
93
- }
94
- },
95
- {
96
- key: "send",
97
- value: (
98
- // compat express res.send, only support etag now
99
- function send(body) {
100
- try {
101
- var generateETag = !this.res.getHeader("ETag") && this.options.etag;
102
- if (body !== void 0 && generateETag) {
103
- var encoding = typeof body === "string" ? "utf-8" : void 0;
104
- var buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
105
- var etag = createEtag(buf, {
106
- weak: true
107
- });
108
- if (etag) {
109
- this.res.setHeader("ETag", etag);
110
- }
111
- }
112
- if (this.fresh) {
113
- this.status = 304;
114
- }
115
- } catch (e) {
116
- this.logger.error(e.message);
117
- }
118
- this.res.end(body);
119
- }
120
- )
121
- },
122
- {
123
- key: "setParams",
124
- value: function setParams(params) {
125
- this.params = params;
126
- }
127
- },
128
- {
129
- key: "setServerData",
130
- value: function setServerData(key, value) {
131
- this.serverData[key] = value;
132
- }
133
- },
134
- {
135
- key: "getReqHeader",
136
- value: function getReqHeader(key) {
137
- var req = this.req;
138
- var field = key.toLowerCase();
139
- switch (field) {
140
- case "referer":
141
- case "referrer":
142
- return req.headers.referrer || req.headers.referer || "";
143
- default:
144
- return req.headers[field] || "";
145
- }
146
- }
147
- },
148
134
  {
149
135
  key: "fresh",
150
136
  get: function get() {
@@ -265,24 +251,6 @@ var ModernServerContext = /* @__PURE__ */ function() {
265
251
  set: function set(statusCode) {
266
252
  this.res.statusCode = statusCode;
267
253
  }
268
- },
269
- {
270
- key: "resHasHandled",
271
- value: (
272
- /**
273
- * 判断链接是否已经关闭
274
- */
275
- function resHasHandled() {
276
- return this.res.writableEnded;
277
- }
278
- )
279
- },
280
- {
281
- key: "error",
282
- value: function error(dig) {
283
- var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
284
- this.logger.error("Web Server Error - ".concat(dig, ", error = %s, req.url = %s, req.headers = %o"), _instanceof(e, Error) ? e.stack || e.message : e, this.path, headersWithoutCookie(this.headers));
285
- }
286
254
  }
287
255
  ]);
288
256
  return ModernServerContext2;
@@ -1,86 +1,55 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
3
  import cookie from "cookie";
6
4
  var BaseResponse = /* @__PURE__ */ function() {
7
5
  "use strict";
8
6
  function BaseResponse2(res) {
9
7
  _class_call_check(this, BaseResponse2);
10
- _define_property(this, "cookies", void 0);
11
- _define_property(this, "res", void 0);
12
8
  this.res = res;
13
9
  this.cookies = {
14
10
  set: this.setCookie.bind(this),
15
11
  clear: this.clearCookie.bind(this)
16
12
  };
17
13
  }
18
- _create_class(BaseResponse2, [
19
- {
20
- key: "get",
21
- value: function get(key) {
22
- return this.res.getHeader(key);
23
- }
24
- },
25
- {
26
- key: "set",
27
- value: function set(key, value) {
28
- return this.res.setHeader(key, value);
29
- }
30
- },
31
- {
32
- key: "status",
33
- value: function status(code) {
34
- this.res.statusCode = code;
35
- }
36
- },
37
- {
38
- key: "setCookie",
39
- value: function setCookie(key, value, options) {
40
- var cookieValue = this.res.getHeader("set-cookie") || "";
41
- var fmt = Array.isArray(cookieValue) ? cookieValue : [
42
- cookieValue
43
- ].filter(Boolean);
44
- fmt.push(cookie.serialize(key, value, options));
45
- this.res.setHeader("set-cookie", fmt.length === 1 ? fmt[0] : fmt);
46
- }
47
- },
48
- {
49
- key: "clearCookie",
50
- value: function clearCookie() {
51
- this.res.removeHeader("set-cookie");
52
- }
53
- },
54
- {
55
- key: "raw",
56
- value: function raw(body, options) {
57
- var _this = this;
58
- var _ref = options || {}, status = _ref.status, _ref_headers = _ref.headers, headers = _ref_headers === void 0 ? {} : _ref_headers;
59
- Object.entries(headers).forEach(function(param) {
60
- var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
61
- _this.res.setHeader(key, value);
62
- });
63
- if (status) {
64
- this.res.statusCode = status;
65
- }
66
- this.res.end(body);
67
- }
14
+ var _proto = BaseResponse2.prototype;
15
+ _proto.get = function get(key) {
16
+ return this.res.getHeader(key);
17
+ };
18
+ _proto.set = function set(key, value) {
19
+ return this.res.setHeader(key, value);
20
+ };
21
+ _proto.status = function status(code) {
22
+ this.res.statusCode = code;
23
+ };
24
+ _proto.setCookie = function setCookie(key, value, options) {
25
+ var cookieValue = this.res.getHeader("set-cookie") || "";
26
+ var fmt = Array.isArray(cookieValue) ? cookieValue : [
27
+ cookieValue
28
+ ].filter(Boolean);
29
+ fmt.push(cookie.serialize(key, value, options));
30
+ this.res.setHeader("set-cookie", fmt.length === 1 ? fmt[0] : fmt);
31
+ };
32
+ _proto.clearCookie = function clearCookie() {
33
+ this.res.removeHeader("set-cookie");
34
+ };
35
+ _proto.raw = function raw(body, options) {
36
+ var _this = this;
37
+ var _ref = options || {}, status = _ref.status, _ref_headers = _ref.headers, headers = _ref_headers === void 0 ? {} : _ref_headers;
38
+ Object.entries(headers).forEach(function(param) {
39
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
40
+ _this.res.setHeader(key, value);
41
+ });
42
+ if (status) {
43
+ this.res.statusCode = status;
68
44
  }
69
- ]);
45
+ this.res.end(body);
46
+ };
70
47
  return BaseResponse2;
71
48
  }();
72
49
  var BaseRequest = /* @__PURE__ */ function() {
73
50
  "use strict";
74
51
  function BaseRequest2(request) {
75
52
  _class_call_check(this, BaseRequest2);
76
- _define_property(this, "url", void 0);
77
- _define_property(this, "host", void 0);
78
- _define_property(this, "pathname", void 0);
79
- _define_property(this, "query", void 0);
80
- _define_property(this, "headers", void 0);
81
- _define_property(this, "cookie", void 0);
82
- _define_property(this, "cookies", void 0);
83
- _define_property(this, "_cookie", void 0);
84
53
  this.url = request.url;
85
54
  this.host = request.host;
86
55
  this.pathname = request.path;
@@ -92,14 +61,10 @@ var BaseRequest = /* @__PURE__ */ function() {
92
61
  get: this.getCookie.bind(this)
93
62
  };
94
63
  }
95
- _create_class(BaseRequest2, [
96
- {
97
- key: "getCookie",
98
- value: function getCookie(key) {
99
- return this._cookie[key];
100
- }
101
- }
102
- ]);
64
+ var _proto = BaseRequest2.prototype;
65
+ _proto.getCookie = function getCookie(key) {
66
+ return this._cookie[key];
67
+ };
103
68
  return BaseRequest2;
104
69
  }();
105
70
  export {
@@ -1,6 +1,5 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
2
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
3
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
5
4
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
6
5
  import { BaseRequest, BaseResponse } from "./base";
@@ -10,11 +9,24 @@ var ServerResponse = /* @__PURE__ */ function() {
10
9
  "use strict";
11
10
  function ServerResponse2(res) {
12
11
  _class_call_check(this, ServerResponse2);
13
- _define_property(this, "locals", void 0);
14
- _define_property(this, "res", void 0);
15
12
  this.res = res;
16
13
  this.locals = res.locals;
17
14
  }
15
+ var _proto = ServerResponse2.prototype;
16
+ _proto.getHeader = function getHeader(key) {
17
+ var _this_res_headers_get;
18
+ return (_this_res_headers_get = this.res.headers.get(key)) !== null && _this_res_headers_get !== void 0 ? _this_res_headers_get : void 0;
19
+ };
20
+ _proto.setHeader = function setHeader(key, value) {
21
+ this.res.headers.set(key, value);
22
+ };
23
+ _proto.removeHeader = function removeHeader(key) {
24
+ this.res.headers.delete(key);
25
+ };
26
+ _proto.end = function end(body) {
27
+ this.res.body = body;
28
+ this.res.isSent = true;
29
+ };
18
30
  _create_class(ServerResponse2, [
19
31
  {
20
32
  key: "statusCode",
@@ -24,32 +36,6 @@ var ServerResponse = /* @__PURE__ */ function() {
24
36
  set: function set(code) {
25
37
  this.res.status = code;
26
38
  }
27
- },
28
- {
29
- key: "getHeader",
30
- value: function getHeader(key) {
31
- var _this_res_headers_get;
32
- return (_this_res_headers_get = this.res.headers.get(key)) !== null && _this_res_headers_get !== void 0 ? _this_res_headers_get : void 0;
33
- }
34
- },
35
- {
36
- key: "setHeader",
37
- value: function setHeader(key, value) {
38
- this.res.headers.set(key, value);
39
- }
40
- },
41
- {
42
- key: "removeHeader",
43
- value: function removeHeader(key) {
44
- this.res.headers.delete(key);
45
- }
46
- },
47
- {
48
- key: "end",
49
- value: function end(body) {
50
- this.res.body = body;
51
- this.res.isSent = true;
52
- }
53
39
  }
54
40
  ]);
55
41
  return ServerResponse2;
@@ -1,39 +1,24 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var RouteAPI = /* @__PURE__ */ function() {
5
3
  "use strict";
6
4
  function RouteAPI2(entryName) {
7
5
  _class_call_check(this, RouteAPI2);
8
- _define_property(this, "current", void 0);
9
- _define_property(this, "status", void 0);
10
- _define_property(this, "url", void 0);
11
6
  this.current = entryName;
12
7
  this.status = 200;
13
8
  this.url = "";
14
9
  }
15
- _create_class(RouteAPI2, [
16
- {
17
- key: "redirect",
18
- value: function redirect(url) {
19
- var status = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 302;
20
- this.url = url;
21
- this.status = status;
22
- }
23
- },
24
- {
25
- key: "rewrite",
26
- value: function rewrite(entryName) {
27
- this.current = entryName;
28
- }
29
- },
30
- {
31
- key: "use",
32
- value: function use(entryName) {
33
- this.rewrite(entryName);
34
- }
35
- }
36
- ]);
10
+ var _proto = RouteAPI2.prototype;
11
+ _proto.redirect = function redirect(url) {
12
+ var status = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 302;
13
+ this.url = url;
14
+ this.status = status;
15
+ };
16
+ _proto.rewrite = function rewrite(entryName) {
17
+ this.current = entryName;
18
+ };
19
+ _proto.use = function use(entryName) {
20
+ this.rewrite(entryName);
21
+ };
37
22
  return RouteAPI2;
38
23
  }();
39
24
  export {
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var RegList = {
5
3
  before: {
6
4
  head: "<head[^>]*>",
@@ -15,67 +13,41 @@ var TemplateAPI = /* @__PURE__ */ function() {
15
13
  "use strict";
16
14
  function TemplateAPI2(content) {
17
15
  _class_call_check(this, TemplateAPI2);
18
- _define_property(this, "content", void 0);
19
16
  this.content = content;
20
17
  }
21
- _create_class(TemplateAPI2, [
22
- {
23
- key: "get",
24
- value: function get() {
25
- return this.content;
26
- }
27
- },
28
- {
29
- key: "set",
30
- value: function set(content) {
31
- this.content = content;
32
- }
33
- },
34
- {
35
- key: "prependHead",
36
- value: function prependHead(fragment) {
37
- var head = RegList.before.head;
38
- return this.replaceByFunction(new RegExp(head), function(beforeHead) {
39
- return "".concat(beforeHead).concat(fragment);
40
- });
41
- }
42
- },
43
- {
44
- key: "appendHead",
45
- value: function appendHead(fragment) {
46
- var head = RegList.after.head;
47
- return this.replace(head, "".concat(fragment).concat(head));
48
- }
49
- },
50
- {
51
- key: "prependBody",
52
- value: function prependBody(fragment) {
53
- var body = RegList.before.body;
54
- return this.replaceByFunction(new RegExp(body), function(beforeBody) {
55
- return "".concat(beforeBody).concat(fragment);
56
- });
57
- }
58
- },
59
- {
60
- key: "appendBody",
61
- value: function appendBody(fragment) {
62
- var body = RegList.after.body;
63
- return this.replace(body, "".concat(fragment).concat(body));
64
- }
65
- },
66
- {
67
- key: "replaceByFunction",
68
- value: function replaceByFunction(reg, replacer) {
69
- this.content = this.content.replace(reg, replacer);
70
- }
71
- },
72
- {
73
- key: "replace",
74
- value: function replace(reg, text) {
75
- this.content = this.content.replace(reg, text);
76
- }
77
- }
78
- ]);
18
+ var _proto = TemplateAPI2.prototype;
19
+ _proto.get = function get() {
20
+ return this.content;
21
+ };
22
+ _proto.set = function set(content) {
23
+ this.content = content;
24
+ };
25
+ _proto.prependHead = function prependHead(fragment) {
26
+ var head = RegList.before.head;
27
+ return this.replaceByFunction(new RegExp(head), function(beforeHead) {
28
+ return "".concat(beforeHead).concat(fragment);
29
+ });
30
+ };
31
+ _proto.appendHead = function appendHead(fragment) {
32
+ var head = RegList.after.head;
33
+ return this.replace(head, "".concat(fragment).concat(head));
34
+ };
35
+ _proto.prependBody = function prependBody(fragment) {
36
+ var body = RegList.before.body;
37
+ return this.replaceByFunction(new RegExp(body), function(beforeBody) {
38
+ return "".concat(beforeBody).concat(fragment);
39
+ });
40
+ };
41
+ _proto.appendBody = function appendBody(fragment) {
42
+ var body = RegList.after.body;
43
+ return this.replace(body, "".concat(fragment).concat(body));
44
+ };
45
+ _proto.replaceByFunction = function replaceByFunction(reg, replacer) {
46
+ this.content = this.content.replace(reg, replacer);
47
+ };
48
+ _proto.replace = function replace(reg, text) {
49
+ this.content = this.content.replace(reg, text);
50
+ };
79
51
  return TemplateAPI2;
80
52
  }();
81
53
  export {
@@ -10,7 +10,7 @@ import { injectServerDataStream, injectServerData } from "./utils";
10
10
  import { ssrCache } from "./ssrCache";
11
11
  var render = function() {
12
12
  var _ref = _async_to_generator(function(ctx, renderOptions, runner) {
13
- var _ctx_res, distDir, route, template, staticGenerate, _renderOptions_enableUnsafeCtx, enableUnsafeCtx, nonce, urlPath, bundle, entryName, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, isSpider, context, bundleJSContent, serverRender, content, _context_redirection, url, _context_redirection_status, status, contentStream, afterStreamingRenderContext;
13
+ var _ctx_res, distDir, route, template, staticGenerate, _renderOptions_enableUnsafeCtx, enableUnsafeCtx, nonce, urlPath, bundle, entryName, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, isSpider, context, bundleJSContent, serverRender, _ref2, content, cacheStatus, _context_redirection, url, _context_redirection_status, status, headers, contentStream, afterStreamingRenderContext;
14
14
  return _ts_generator(this, function(_state) {
15
15
  switch (_state.label) {
16
16
  case 0:
@@ -72,7 +72,7 @@ var render = function() {
72
72
  ssrCache(ctx.req, serverRender, context)
73
73
  ];
74
74
  case 2:
75
- content = _state.sent();
75
+ _ref2 = _state.sent(), content = _ref2.data, cacheStatus = _ref2.status;
76
76
  _context_redirection = context.redirection, url = _context_redirection.url, _context_redirection_status = _context_redirection.status, status = _context_redirection_status === void 0 ? 302 : _context_redirection_status;
77
77
  if (url) {
78
78
  return [
@@ -85,12 +85,15 @@ var render = function() {
85
85
  }
86
86
  ];
87
87
  }
88
+ headers = {};
89
+ cacheStatus && (headers["x-render-cache"] = cacheStatus);
88
90
  if (typeof content === "string") {
89
91
  return [
90
92
  2,
91
93
  {
92
94
  content: injectServerData(content, ctx),
93
- contentType: mime.contentType("html")
95
+ contentType: mime.contentType("html"),
96
+ headers
94
97
  }
95
98
  ];
96
99
  } else {
@@ -110,7 +113,8 @@ var render = function() {
110
113
  {
111
114
  content: "",
112
115
  contentStream,
113
- contentType: mime.contentType("html")
116
+ contentType: mime.contentType("html"),
117
+ headers
114
118
  }
115
119
  ];
116
120
  }
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import path from "path";
5
3
  import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
6
4
  var CACHE_FILENAME = "cache";
@@ -8,23 +6,17 @@ var ServerCacheMod = /* @__PURE__ */ function() {
8
6
  "use strict";
9
7
  function ServerCacheMod2() {
10
8
  _class_call_check(this, ServerCacheMod2);
11
- _define_property(this, "customContainer", void 0);
12
- _define_property(this, "cacheOption", void 0);
13
9
  }
14
- _create_class(ServerCacheMod2, [
15
- {
16
- key: "loadServerCacheMod",
17
- value: function loadServerCacheMod() {
18
- var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
19
- var serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
20
- var mod = requireExistModule(serverCacheFilepath, {
21
- interop: false
22
- });
23
- this.customContainer = mod === null || mod === void 0 ? void 0 : mod.customContainer;
24
- this.cacheOption = mod === null || mod === void 0 ? void 0 : mod.cacheOption;
25
- }
26
- }
27
- ]);
10
+ var _proto = ServerCacheMod2.prototype;
11
+ _proto.loadServerCacheMod = function loadServerCacheMod() {
12
+ var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
13
+ var serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
14
+ var mod = requireExistModule(serverCacheFilepath, {
15
+ interop: false
16
+ });
17
+ this.customContainer = mod === null || mod === void 0 ? void 0 : mod.customContainer;
18
+ this.cacheOption = mod === null || mod === void 0 ? void 0 : mod.cacheOption;
19
+ };
28
20
  return ServerCacheMod2;
29
21
  }();
30
22
  var cacheMod = new ServerCacheMod();