@module-federation/modern-js 0.18.2 → 0.18.4

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.
@@ -28,26 +28,31 @@ const staticServePlugin = () => ({
28
28
  setup: (api) => {
29
29
  api.onPrepare(() => {
30
30
  var _config_output, _config_server;
31
- console.log(process.env.NODE_ENV);
32
31
  if (process.env.NODE_ENV === "development") {
33
32
  return;
34
33
  }
35
34
  const { middlewares } = api.getServerContext();
36
35
  const config = api.getServerConfig();
37
36
  const assetPrefix = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.assetPrefix) || "";
38
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr)) {
39
- return;
37
+ if ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) {
38
+ const context = api.getServerContext();
39
+ const pwd = context.distDirectory;
40
+ const serverStaticMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
41
+ assetPrefix,
42
+ pwd
43
+ });
44
+ middlewares.push({
45
+ name: "module-federation-serve-manifest",
46
+ handler: serverStaticMiddleware
47
+ });
48
+ }
49
+ if (process.env.MODERN_MF_AUTO_CORS) {
50
+ const corsMiddleware = (0, import_staticMiddleware.createCorsMiddleware)();
51
+ middlewares.push({
52
+ name: "module-federation-cors",
53
+ handler: corsMiddleware
54
+ });
40
55
  }
41
- const context = api.getServerContext();
42
- const pwd = context.distDirectory;
43
- const serverStaticMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
44
- assetPrefix,
45
- pwd
46
- });
47
- middlewares.push({
48
- name: "module-federation-serve-manifest",
49
- handler: serverStaticMiddleware
50
- });
51
56
  });
52
57
  }
53
58
  });
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var staticMiddleware_exports = {};
30
30
  __export(staticMiddleware_exports, {
31
+ createCorsMiddleware: () => createCorsMiddleware,
31
32
  createStaticMiddleware: () => createStaticMiddleware
32
33
  });
33
34
  module.exports = __toCommonJS(staticMiddleware_exports);
@@ -71,7 +72,19 @@ const createStaticMiddleware = (options) => {
71
72
  return c.body(fileResult.content, 200);
72
73
  };
73
74
  };
75
+ const createCorsMiddleware = () => {
76
+ return async (c, next) => {
77
+ const pathname = c.req.path;
78
+ if (import_node_path.default.extname(pathname)) {
79
+ c.header("Access-Control-Allow-Origin", "*");
80
+ c.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
81
+ c.header("Access-Control-Allow-Headers", "*");
82
+ }
83
+ return next();
84
+ };
85
+ };
74
86
  // Annotate the CommonJS export names for ESM import in node:
75
87
  0 && (module.exports = {
88
+ createCorsMiddleware,
76
89
  createStaticMiddleware
77
90
  });
@@ -1,30 +1,35 @@
1
- import { createStaticMiddleware } from "./staticMiddleware";
1
+ import { createCorsMiddleware, createStaticMiddleware } from "./staticMiddleware";
2
2
  var staticServePlugin = function() {
3
3
  return {
4
4
  name: "@modern-js/module-federation/server",
5
5
  setup: function(api) {
6
6
  api.onPrepare(function() {
7
7
  var _config_output, _config_server;
8
- console.log(process.env.NODE_ENV);
9
8
  if (process.env.NODE_ENV === "development") {
10
9
  return;
11
10
  }
12
11
  var middlewares = api.getServerContext().middlewares;
13
12
  var config = api.getServerConfig();
14
13
  var assetPrefix = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.assetPrefix) || "";
15
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr)) {
16
- return;
14
+ if ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) {
15
+ var context = api.getServerContext();
16
+ var pwd = context.distDirectory;
17
+ var serverStaticMiddleware = createStaticMiddleware({
18
+ assetPrefix,
19
+ pwd
20
+ });
21
+ middlewares.push({
22
+ name: "module-federation-serve-manifest",
23
+ handler: serverStaticMiddleware
24
+ });
25
+ }
26
+ if (process.env.MODERN_MF_AUTO_CORS) {
27
+ var corsMiddleware = createCorsMiddleware();
28
+ middlewares.push({
29
+ name: "module-federation-cors",
30
+ handler: corsMiddleware
31
+ });
17
32
  }
18
- var context = api.getServerContext();
19
- var pwd = context.distDirectory;
20
- var serverStaticMiddleware = createStaticMiddleware({
21
- assetPrefix,
22
- pwd
23
- });
24
- middlewares.push({
25
- name: "module-federation-serve-manifest",
26
- handler: serverStaticMiddleware
27
- });
28
33
  });
29
34
  }
30
35
  };
@@ -76,6 +76,29 @@ var createStaticMiddleware = function(options) {
76
76
  };
77
77
  }();
78
78
  };
79
+ var createCorsMiddleware = function() {
80
+ return function() {
81
+ var _ref = _async_to_generator(function(c, next) {
82
+ var pathname;
83
+ return _ts_generator(this, function(_state) {
84
+ pathname = c.req.path;
85
+ if (path.extname(pathname)) {
86
+ c.header("Access-Control-Allow-Origin", "*");
87
+ c.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
88
+ c.header("Access-Control-Allow-Headers", "*");
89
+ }
90
+ return [
91
+ 2,
92
+ next()
93
+ ];
94
+ });
95
+ });
96
+ return function(c, next) {
97
+ return _ref.apply(this, arguments);
98
+ };
99
+ }();
100
+ };
79
101
  export {
102
+ createCorsMiddleware,
80
103
  createStaticMiddleware
81
104
  };
@@ -1,29 +1,34 @@
1
- import { createStaticMiddleware } from "./staticMiddleware";
1
+ import { createCorsMiddleware, createStaticMiddleware } from "./staticMiddleware";
2
2
  const staticServePlugin = () => ({
3
3
  name: "@modern-js/module-federation/server",
4
4
  setup: (api) => {
5
5
  api.onPrepare(() => {
6
6
  var _config_output, _config_server;
7
- console.log(process.env.NODE_ENV);
8
7
  if (process.env.NODE_ENV === "development") {
9
8
  return;
10
9
  }
11
10
  const { middlewares } = api.getServerContext();
12
11
  const config = api.getServerConfig();
13
12
  const assetPrefix = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.assetPrefix) || "";
14
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr)) {
15
- return;
13
+ if ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) {
14
+ const context = api.getServerContext();
15
+ const pwd = context.distDirectory;
16
+ const serverStaticMiddleware = createStaticMiddleware({
17
+ assetPrefix,
18
+ pwd
19
+ });
20
+ middlewares.push({
21
+ name: "module-federation-serve-manifest",
22
+ handler: serverStaticMiddleware
23
+ });
24
+ }
25
+ if (process.env.MODERN_MF_AUTO_CORS) {
26
+ const corsMiddleware = createCorsMiddleware();
27
+ middlewares.push({
28
+ name: "module-federation-cors",
29
+ handler: corsMiddleware
30
+ });
16
31
  }
17
- const context = api.getServerContext();
18
- const pwd = context.distDirectory;
19
- const serverStaticMiddleware = createStaticMiddleware({
20
- assetPrefix,
21
- pwd
22
- });
23
- middlewares.push({
24
- name: "module-federation-serve-manifest",
25
- handler: serverStaticMiddleware
26
- });
27
32
  });
28
33
  }
29
34
  });
@@ -38,6 +38,18 @@ const createStaticMiddleware = (options) => {
38
38
  return c.body(fileResult.content, 200);
39
39
  };
40
40
  };
41
+ const createCorsMiddleware = () => {
42
+ return async (c, next) => {
43
+ const pathname = c.req.path;
44
+ if (path.extname(pathname)) {
45
+ c.header("Access-Control-Allow-Origin", "*");
46
+ c.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
47
+ c.header("Access-Control-Allow-Headers", "*");
48
+ }
49
+ return next();
50
+ };
51
+ };
41
52
  export {
53
+ createCorsMiddleware,
42
54
  createStaticMiddleware
43
55
  };
@@ -3,4 +3,5 @@ declare const createStaticMiddleware: (options: {
3
3
  assetPrefix: string;
4
4
  pwd: string;
5
5
  }) => MiddlewareHandler;
6
- export { createStaticMiddleware };
6
+ declare const createCorsMiddleware: () => MiddlewareHandler;
7
+ export { createStaticMiddleware, createCorsMiddleware };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.18.2",
3
+ "version": "0.18.4",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -119,13 +119,13 @@
119
119
  "@swc/helpers": "^0.5.17",
120
120
  "node-fetch": "~3.3.0",
121
121
  "react-error-boundary": "4.1.2",
122
- "@module-federation/rsbuild-plugin": "0.18.2",
123
- "@module-federation/bridge-react": "0.18.2",
124
- "@module-federation/enhanced": "0.18.2",
125
- "@module-federation/runtime": "0.18.2",
126
- "@module-federation/node": "2.7.13",
127
- "@module-federation/sdk": "0.18.2",
128
- "@module-federation/cli": "0.18.2"
122
+ "@module-federation/rsbuild-plugin": "0.18.4",
123
+ "@module-federation/bridge-react": "0.18.4",
124
+ "@module-federation/enhanced": "0.18.4",
125
+ "@module-federation/runtime": "0.18.4",
126
+ "@module-federation/node": "2.7.15",
127
+ "@module-federation/sdk": "0.18.4",
128
+ "@module-federation/cli": "0.18.4"
129
129
  },
130
130
  "devDependencies": {
131
131
  "@modern-js/core": "2.68.2",
@@ -137,7 +137,7 @@
137
137
  "@modern-js/tsconfig": "2.68.2",
138
138
  "@types/react": "^18.3.11",
139
139
  "@types/react-dom": "^18.3.0",
140
- "@module-federation/manifest": "0.18.2"
140
+ "@module-federation/manifest": "0.18.4"
141
141
  },
142
142
  "peerDependencies": {
143
143
  "react": ">=17",