@umijs/server 4.0.0-rc.1 → 4.0.0-rc.12

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.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RequestHandler } from 'express';
1
+ import type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
2
2
  export interface IOpts {
3
3
  base: string;
4
4
  routes: Record<string, {
@@ -18,6 +18,7 @@ export interface IOpts {
18
18
  modifyHTML?: (html: string, args: {
19
19
  path?: string;
20
20
  }) => Promise<string>;
21
+ historyType?: 'hash' | 'browser';
21
22
  }
22
23
  export declare function getMarkup(opts: Omit<IOpts, 'routes'> & {
23
24
  path?: 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
- const react_router_dom_1 = require("react-router-dom");
19
- const routes_1 = require("./routes");
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,13 +94,20 @@ 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
- // 匹配路由,不匹配走 next()
98
- // TODO: cache
99
- const routes = (0, routes_1.createServerRoutes)({
100
- routesById: opts.routes,
101
- });
102
- const matches = (0, react_router_dom_1.matchRoutes)(routes, req.path, opts.base);
103
- if (matches) {
97
+ var _a;
98
+ if (opts.historyType === 'browser' &&
99
+ opts.base !== '/' &&
100
+ req.path === '/') {
101
+ // 如果是 browser,并且配置了非 / base,访问 / 时 redirect 到 base 路径
102
+ res.redirect(opts.base);
103
+ }
104
+ else if ((_a = req.headers.accept) === null || _a === void 0 ? void 0 : _a.includes('text/html')) {
105
+ // 匹配路由,不匹配走 next()
106
+ // const routes = createServerRoutes({
107
+ // routesById: opts.routes,
108
+ // });
109
+ // const matches = matchRoutes(routes, req.path, opts.base);
110
+ // 其他接受 HTML 的请求都兜底返回 HTML
104
111
  res.set('Content-Type', 'text/html');
105
112
  const markup = yield getMarkup(Object.assign(Object.assign({}, opts), { path: req.path }));
106
113
  res.end(markup);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/server",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.12",
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,13 +20,11 @@
20
20
  "dev": "pnpm build -- --watch"
21
21
  },
22
22
  "dependencies": {
23
- "history": "5.1.0",
24
- "react": "18.0.0-rc.0",
25
- "react-dom": "18.0.0-rc.0",
26
- "react-router-dom": "6.1.1"
27
- },
28
- "devDependencies": {
29
- "@types/express": "4.17.13"
23
+ "@umijs/bundler-utils": "4.0.0-rc.12",
24
+ "history": "5.3.0",
25
+ "react": "17.0.2",
26
+ "react-dom": "17.0.2",
27
+ "react-router-dom": "6.3.0"
30
28
  },
31
29
  "publishConfig": {
32
30
  "access": "public"