@modern-js/prod-server 2.7.0 → 2.9.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,5 +1,27 @@
1
1
  # @modern-js/prod-server
2
2
 
3
+ ## 2.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 49bb8cd0ef: fix: move chunkmap.css comment to bottom of head
8
+ fix: 将 chunkmap.css 标记移动到 head 底部
9
+ - @modern-js/server-core@2.9.0
10
+ - @modern-js/utils@2.9.0
11
+
12
+ ## 2.8.0
13
+
14
+ ### Patch Changes
15
+
16
+ - 1104a9f18b: feat: support start web service only
17
+ feat: 支持只启动 web 服务
18
+ - 70d82e1408: fix: use mock host instead real url host for url parse, for new URL not support ipv6, and we only need parse url path & search
19
+ fix: 使用虚拟的域名代替真实的主机名,因为 new URL 不支持解析 ipv6 的域名,并且我们只需要解析 url 的路径和查询字符串
20
+ - Updated dependencies [1104a9f18b]
21
+ - Updated dependencies [1f6ca2c7fb]
22
+ - @modern-js/utils@2.8.0
23
+ - @modern-js/server-core@2.8.0
24
+
3
25
  ## 2.7.0
4
26
 
5
27
  ### Minor Changes
package/README.md CHANGED
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
19
19
 
20
20
  ## Contributing
21
21
 
22
- Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
23
 
24
24
  ## License
25
25
 
26
- Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -36,6 +36,7 @@ var import_buffer = require("buffer");
36
36
  var import_etag = __toESM(require("etag"));
37
37
  var import_fresh = __toESM(require("fresh"));
38
38
  var import_utils = require("../../utils");
39
+ const MOCK_URL_BASE = "https://modernjs.dev/";
39
40
  class ModernServerContext {
40
41
  constructor(req, res, options) {
41
42
  /**
@@ -55,6 +56,10 @@ class ModernServerContext {
55
56
  get metrics() {
56
57
  return this.req.metrics;
57
58
  }
59
+ get parsedURL() {
60
+ const url = new import_url.URL(this.req.url, MOCK_URL_BASE);
61
+ return url;
62
+ }
58
63
  bind() {
59
64
  const { req, res } = this;
60
65
  req.get = (key) => this.getReqHeader(key);
@@ -146,23 +151,17 @@ class ModernServerContext {
146
151
  get href() {
147
152
  return this.origin + this.url;
148
153
  }
149
- get parsedURL() {
150
- const url = new import_url.URL(this.req.url, this.origin);
151
- return url;
152
- }
153
154
  get path() {
154
155
  return this.parsedURL.pathname;
155
156
  }
156
157
  set path(p) {
157
- const url = new import_url.URL(this.req.url, this.origin);
158
- if (!url || !p) {
158
+ if (!p) {
159
159
  return;
160
160
  }
161
- if (url.pathname === p) {
161
+ if (this.path === p) {
162
162
  return;
163
163
  }
164
- url.pathname = p;
165
- this.url = url.toString();
164
+ this.url = p + this.parsedURL.search;
166
165
  }
167
166
  get querystring() {
168
167
  if (!this.req) {
@@ -223,6 +223,13 @@ class ModernServer {
223
223
  const { workDir, runner, conf } = this;
224
224
  const { bff } = conf;
225
225
  const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
226
+ const webOnly = await (0, import_utils.isWebOnly)();
227
+ if (webOnly && process.env.NODE_ENV === "development") {
228
+ return (req, res) => {
229
+ res.setHeader("Content-Type", "text/plain");
230
+ res.end(JSON.stringify(""));
231
+ };
232
+ }
226
233
  return runner.prepareApiServer(
227
234
  {
228
235
  pwd: workDir,
@@ -43,6 +43,7 @@ import { Buffer } from "buffer";
43
43
  import createEtag from "etag";
44
44
  import fresh from "fresh";
45
45
  import { headersWithoutCookie } from "../../utils";
46
+ var MOCK_URL_BASE = "https://modernjs.dev/";
46
47
  var ModernServerContext = /*#__PURE__*/ function() {
47
48
  "use strict";
48
49
  function ModernServerContext(req, res, options) {
@@ -77,6 +78,13 @@ var ModernServerContext = /*#__PURE__*/ function() {
77
78
  return this.req.metrics;
78
79
  }
79
80
  },
81
+ {
82
+ key: "parsedURL",
83
+ get: function get() {
84
+ var url = new URL(this.req.url, MOCK_URL_BASE);
85
+ return url;
86
+ }
87
+ },
80
88
  {
81
89
  key: "bind",
82
90
  value: function bind() {
@@ -213,28 +221,19 @@ var ModernServerContext = /*#__PURE__*/ function() {
213
221
  return this.origin + this.url;
214
222
  }
215
223
  },
216
- {
217
- key: "parsedURL",
218
- get: function get() {
219
- var url = new URL(this.req.url, this.origin);
220
- return url;
221
- }
222
- },
223
224
  {
224
225
  key: "path",
225
226
  get: function get() {
226
227
  return this.parsedURL.pathname;
227
228
  },
228
229
  set: function set(p) {
229
- var url = new URL(this.req.url, this.origin);
230
- if (!url || !p) {
230
+ if (!p) {
231
231
  return;
232
232
  }
233
- if (url.pathname === p) {
233
+ if (this.path === p) {
234
234
  return;
235
235
  }
236
- url.pathname = p;
237
- this.url = url.toString();
236
+ this.url = p + this.parsedURL.search;
238
237
  }
239
238
  },
240
239
  {
@@ -198,7 +198,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
198
198
  };
199
199
  import { createServer } from "http";
200
200
  import path from "path";
201
- import { fs, isPromise, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
201
+ import { fs, isPromise, isWebOnly, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
202
202
  import { RouteMatchManager } from "../libs/route";
203
203
  import { createRenderHandler } from "../libs/render";
204
204
  import { createStaticFileHandler, faviconFallbackHandler } from "../libs/serveFile";
@@ -600,25 +600,43 @@ var ModernServer = /*#__PURE__*/ function() {
600
600
  value: function prepareAPIHandler(extension) {
601
601
  var _this = this;
602
602
  return _asyncToGenerator(function() {
603
- var workDir, runner, conf, bff, prefix;
603
+ var workDir, runner, conf, bff, prefix, webOnly;
604
604
  return __generator(this, function(_state) {
605
- workDir = _this.workDir, runner = _this.runner, conf = _this.conf;
606
- bff = conf.bff;
607
- prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
608
- return [
609
- 2,
610
- runner.prepareApiServer({
611
- pwd: workDir,
612
- config: extension,
613
- prefix: Array.isArray(prefix) ? prefix[0] : prefix,
614
- httpMethodDecider: bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider,
615
- render: _this.render.bind(_this)
616
- }, {
617
- onLast: function() {
618
- return null;
605
+ switch(_state.label){
606
+ case 0:
607
+ workDir = _this.workDir, runner = _this.runner, conf = _this.conf;
608
+ bff = conf.bff;
609
+ prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
610
+ return [
611
+ 4,
612
+ isWebOnly()
613
+ ];
614
+ case 1:
615
+ webOnly = _state.sent();
616
+ if (webOnly && process.env.NODE_ENV === "development") {
617
+ return [
618
+ 2,
619
+ function(req, res) {
620
+ res.setHeader("Content-Type", "text/plain");
621
+ res.end(JSON.stringify(""));
622
+ }
623
+ ];
619
624
  }
620
- })
621
- ];
625
+ return [
626
+ 2,
627
+ runner.prepareApiServer({
628
+ pwd: workDir,
629
+ config: extension,
630
+ prefix: Array.isArray(prefix) ? prefix[0] : prefix,
631
+ httpMethodDecider: bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider,
632
+ render: _this.render.bind(_this)
633
+ }, {
634
+ onLast: function() {
635
+ return null;
636
+ }
637
+ })
638
+ ];
639
+ }
622
640
  });
623
641
  })();
624
642
  }
@@ -4,6 +4,7 @@ import { Buffer } from "buffer";
4
4
  import createEtag from "etag";
5
5
  import fresh from "fresh";
6
6
  import { headersWithoutCookie } from "../../utils";
7
+ const MOCK_URL_BASE = "https://modernjs.dev/";
7
8
  class ModernServerContext {
8
9
  constructor(req, res, options) {
9
10
  /**
@@ -23,6 +24,10 @@ class ModernServerContext {
23
24
  get metrics() {
24
25
  return this.req.metrics;
25
26
  }
27
+ get parsedURL() {
28
+ const url = new URL(this.req.url, MOCK_URL_BASE);
29
+ return url;
30
+ }
26
31
  bind() {
27
32
  const { req, res } = this;
28
33
  req.get = (key) => this.getReqHeader(key);
@@ -114,23 +119,17 @@ class ModernServerContext {
114
119
  get href() {
115
120
  return this.origin + this.url;
116
121
  }
117
- get parsedURL() {
118
- const url = new URL(this.req.url, this.origin);
119
- return url;
120
- }
121
122
  get path() {
122
123
  return this.parsedURL.pathname;
123
124
  }
124
125
  set path(p) {
125
- const url = new URL(this.req.url, this.origin);
126
- if (!url || !p) {
126
+ if (!p) {
127
127
  return;
128
128
  }
129
- if (url.pathname === p) {
129
+ if (this.path === p) {
130
130
  return;
131
131
  }
132
- url.pathname = p;
133
- this.url = url.toString();
132
+ this.url = p + this.parsedURL.search;
134
133
  }
135
134
  get querystring() {
136
135
  if (!this.req) {
@@ -1,6 +1,12 @@
1
1
  import { createServer } from "http";
2
2
  import path from "path";
3
- import { fs, isPromise, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
3
+ import {
4
+ fs,
5
+ isPromise,
6
+ isWebOnly,
7
+ mime,
8
+ ROUTE_SPEC_FILE
9
+ } from "@modern-js/utils";
4
10
  import {
5
11
  RouteMatchManager
6
12
  } from "../libs/route";
@@ -213,6 +219,13 @@ class ModernServer {
213
219
  const { workDir, runner, conf } = this;
214
220
  const { bff } = conf;
215
221
  const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
222
+ const webOnly = await isWebOnly();
223
+ if (webOnly && process.env.NODE_ENV === "development") {
224
+ return (req, res) => {
225
+ res.setHeader("Content-Type", "text/plain");
226
+ res.end(JSON.stringify(""));
227
+ };
228
+ }
216
229
  return runner.prepareApiServer(
217
230
  {
218
231
  pwd: workDir,
@@ -1,11 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
- /// <reference types="node" />
5
4
  /// <reference types="node/http" />
6
- /// <reference types=".dts-temp/NtW8DT-FXC5GraMEoP2PI/src/type" />
5
+ /// <reference types=".dts-temp/XV7p0812FeqQvmefgYASU/src/type" />
7
6
  import { IncomingMessage, ServerResponse } from 'http';
8
- import { URL } from 'url';
9
7
  import qs from 'querystring';
10
8
  import type { ModernServerContext as ModernServerContextInterface } from '@modern-js/types';
11
9
  export type ContextOptions = {
@@ -32,6 +30,7 @@ export declare class ModernServerContext implements ModernServerContextInterface
32
30
  serverData: Record<string, any>;
33
31
  private options;
34
32
  constructor(req: IncomingMessage, res: ServerResponse, options?: ContextOptions);
33
+ private get parsedURL();
35
34
  private bind;
36
35
  send(body: ResponseBody): void;
37
36
  setParams(params: Record<string, string>): void;
@@ -46,7 +45,6 @@ export declare class ModernServerContext implements ModernServerContextInterface
46
45
  get protocol(): string;
47
46
  get origin(): string;
48
47
  get href(): string;
49
- get parsedURL(): URL;
50
48
  get path(): string;
51
49
  set path(p: string);
52
50
  get querystring(): string;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node/http" />
3
- /// <reference types=".dts-temp/NtW8DT-FXC5GraMEoP2PI/src/type" />
3
+ /// <reference types=".dts-temp/XV7p0812FeqQvmefgYASU/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
@@ -2,8 +2,8 @@
2
2
  "name": "@modern-js/prod-server",
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": "web-infra-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
9
  "react",
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.7.0",
14
+ "version": "2.9.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -54,8 +54,8 @@
54
54
  "merge-deep": "^3.0.3",
55
55
  "path-to-regexp": "^6.2.0",
56
56
  "serve-static": "^1.14.1",
57
- "@modern-js/utils": "2.7.0",
58
- "@modern-js/server-core": "2.7.0"
57
+ "@modern-js/utils": "2.9.0",
58
+ "@modern-js/server-core": "2.9.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/cookie": "^0.4.1",
@@ -71,10 +71,10 @@
71
71
  "node-mocks-http": "^1.11.0",
72
72
  "portfinder": "^1.0.28",
73
73
  "typescript": "^4",
74
- "@modern-js/types": "2.7.0",
75
- "@modern-js/server-core": "2.7.0",
76
- "@scripts/jest-config": "2.7.0",
77
- "@scripts/build": "2.7.0"
74
+ "@modern-js/types": "2.9.0",
75
+ "@modern-js/server-core": "2.9.0",
76
+ "@scripts/jest-config": "2.9.0",
77
+ "@scripts/build": "2.9.0"
78
78
  },
79
79
  "sideEffects": false,
80
80
  "publishConfig": {