@umijs/server 4.0.0-rc.10 → 4.0.0-rc.13
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/server.js +15 -24
- package/package.json +3 -3
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) {
|
|
@@ -94,35 +94,26 @@ function getMarkup(opts) {
|
|
|
94
94
|
exports.getMarkup = getMarkup;
|
|
95
95
|
function createRequestHandler(opts) {
|
|
96
96
|
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
var _a;
|
|
98
|
+
if (opts.historyType === 'browser' &&
|
|
99
|
+
opts.base !== '/' &&
|
|
100
|
+
req.path === '/') {
|
|
101
|
+
// 如果是 browser,并且配置了非 / base,访问 / 时 redirect 到 base 路径
|
|
102
|
+
res.redirect(opts.base);
|
|
102
103
|
}
|
|
103
|
-
else {
|
|
104
|
+
else if ((_a = req.headers.accept) === null || _a === void 0 ? void 0 : _a.includes('text/html')) {
|
|
104
105
|
// 匹配路由,不匹配走 next()
|
|
105
|
-
const routes =
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
const matches =
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
if (isMatch) {
|
|
106
|
+
// const routes = createServerRoutes({
|
|
107
|
+
// routesById: opts.routes,
|
|
108
|
+
// });
|
|
109
|
+
// const matches = matchRoutes(routes, req.path, opts.base);
|
|
110
|
+
// 其他接受 HTML 的请求都兜底返回 HTML
|
|
112
111
|
res.set('Content-Type', 'text/html');
|
|
113
112
|
const markup = yield getMarkup(Object.assign(Object.assign({}, opts), { path: req.path }));
|
|
114
113
|
res.end(markup);
|
|
115
114
|
}
|
|
116
115
|
else {
|
|
117
|
-
|
|
118
|
-
if (opts.historyType === 'browser' &&
|
|
119
|
-
opts.base !== '/' &&
|
|
120
|
-
req.path === '/') {
|
|
121
|
-
res.redirect(opts.base);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
next();
|
|
125
|
-
}
|
|
116
|
+
next();
|
|
126
117
|
}
|
|
127
118
|
});
|
|
128
119
|
}
|
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.13",
|
|
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",
|
|
@@ -20,11 +20,11 @@
|
|
|
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.13",
|
|
24
24
|
"history": "5.3.0",
|
|
25
25
|
"react": "17.0.2",
|
|
26
26
|
"react-dom": "17.0.2",
|
|
27
|
-
"react-router-dom": "6.
|
|
27
|
+
"react-router-dom": "6.3.0"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|