@umijs/server 4.0.0-rc.11 → 4.0.0-rc.14
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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +17 -24
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,4 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createServerRoutes = void 0;
|
|
18
|
+
var routes_1 = require("./routes");
|
|
19
|
+
Object.defineProperty(exports, "createServerRoutes", { enumerable: true, get: function () { return routes_1.createServerRoutes; } });
|
|
17
20
|
__exportStar(require("./server"), exports);
|
package/dist/server.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface IOpts {
|
|
|
11
11
|
metas?: Record<string, string>[];
|
|
12
12
|
styles?: (Record<string, string> | string)[];
|
|
13
13
|
favicon?: string;
|
|
14
|
+
title?: string;
|
|
14
15
|
headScripts?: (Record<string, string> | string)[];
|
|
15
16
|
scripts?: (Record<string, string> | string)[];
|
|
16
17
|
mountElementId?: string;
|
package/dist/server.js
CHANGED
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.createRequestHandler = exports.getMarkup = void 0;
|
|
16
16
|
const react_1 = __importDefault(require("react"));
|
|
17
17
|
const server_1 = __importDefault(require("react-dom/server"));
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// import { matchRoutes } from 'react-router-dom';
|
|
19
|
+
// import { createServerRoutes } from './routes';
|
|
20
20
|
const scripts_1 = require("./scripts");
|
|
21
21
|
const styles_1 = require("./styles");
|
|
22
22
|
function getMarkup(opts) {
|
|
@@ -56,6 +56,7 @@ function getMarkup(opts) {
|
|
|
56
56
|
const favicon = opts.favicon
|
|
57
57
|
? `<link rel="shortcut icon" href="${opts.favicon}">`
|
|
58
58
|
: '';
|
|
59
|
+
const title = opts.title ? `<title>${opts.title}</title>` : '';
|
|
59
60
|
const metas = (opts.metas || []).map((meta) => getTagContent({ attrs: meta, tagName: 'meta' }));
|
|
60
61
|
const links = (opts.links || []).map((link) => getTagContent({ attrs: link, tagName: 'link' }));
|
|
61
62
|
const styles = (0, styles_1.normalizeStyles)(opts.styles || []).map(getStyleContent);
|
|
@@ -73,6 +74,7 @@ function getMarkup(opts) {
|
|
|
73
74
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />`,
|
|
74
75
|
metas.join('\n'),
|
|
75
76
|
favicon,
|
|
77
|
+
title,
|
|
76
78
|
links.join('\n'),
|
|
77
79
|
styles.join('\n'),
|
|
78
80
|
headScripts.join('\n'),
|
|
@@ -94,35 +96,26 @@ function getMarkup(opts) {
|
|
|
94
96
|
exports.getMarkup = getMarkup;
|
|
95
97
|
function createRequestHandler(opts) {
|
|
96
98
|
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
var _a;
|
|
100
|
+
if (opts.historyType === 'browser' &&
|
|
101
|
+
opts.base !== '/' &&
|
|
102
|
+
req.path === '/') {
|
|
103
|
+
// 如果是 browser,并且配置了非 / base,访问 / 时 redirect 到 base 路径
|
|
104
|
+
res.redirect(opts.base);
|
|
102
105
|
}
|
|
103
|
-
else {
|
|
106
|
+
else if ((_a = req.headers.accept) === null || _a === void 0 ? void 0 : _a.includes('text/html')) {
|
|
104
107
|
// 匹配路由,不匹配走 next()
|
|
105
|
-
const routes =
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
const matches =
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
if (isMatch) {
|
|
108
|
+
// const routes = createServerRoutes({
|
|
109
|
+
// routesById: opts.routes,
|
|
110
|
+
// });
|
|
111
|
+
// const matches = matchRoutes(routes, req.path, opts.base);
|
|
112
|
+
// 其他接受 HTML 的请求都兜底返回 HTML
|
|
112
113
|
res.set('Content-Type', 'text/html');
|
|
113
114
|
const markup = yield getMarkup(Object.assign(Object.assign({}, opts), { path: req.path }));
|
|
114
115
|
res.end(markup);
|
|
115
116
|
}
|
|
116
117
|
else {
|
|
117
|
-
|
|
118
|
-
if (opts.historyType === 'browser' &&
|
|
119
|
-
opts.base !== '/' &&
|
|
120
|
-
req.path === '/') {
|
|
121
|
-
res.redirect(opts.base);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
next();
|
|
125
|
-
}
|
|
118
|
+
next();
|
|
126
119
|
}
|
|
127
120
|
});
|
|
128
121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/server",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.14",
|
|
4
4
|
"description": "@umijs/server",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/server#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "pnpm tsc",
|
|
19
|
-
"build:deps": "
|
|
19
|
+
"build:deps": "umi-scripts bundleDeps",
|
|
20
20
|
"dev": "pnpm build -- --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
23
|
+
"@umijs/bundler-utils": "4.0.0-rc.14",
|
|
24
24
|
"history": "5.3.0",
|
|
25
|
-
"react": "
|
|
26
|
-
"react-dom": "
|
|
27
|
-
"react-router-dom": "6.
|
|
25
|
+
"react": "18.1.0",
|
|
26
|
+
"react-dom": "18.1.0",
|
|
27
|
+
"react-router-dom": "6.3.0"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|