@umijs/server 4.0.0-beta.6 → 4.0.0-rc.1
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/scripts.js +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.js +3 -3
- package/dist/styles.js +1 -1
- package/package.json +19 -19
package/dist/scripts.js
CHANGED
|
@@ -13,7 +13,7 @@ const RE_URL = /^(http:|https:)?\/\//;
|
|
|
13
13
|
function normalizeScript(script) {
|
|
14
14
|
if (typeof script === 'string') {
|
|
15
15
|
const isUrl = RE_URL.test(script) ||
|
|
16
|
-
script.startsWith('/') ||
|
|
16
|
+
(script.startsWith('/') && !script.startsWith('/*')) ||
|
|
17
17
|
script.startsWith('./') ||
|
|
18
18
|
script.startsWith('../');
|
|
19
19
|
return isUrl
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RequestHandler } from 'express';
|
|
2
|
-
interface IOpts {
|
|
2
|
+
export interface IOpts {
|
|
3
|
+
base: string;
|
|
3
4
|
routes: Record<string, {
|
|
4
5
|
path: string;
|
|
5
6
|
file: string;
|
|
@@ -12,6 +13,7 @@ interface IOpts {
|
|
|
12
13
|
favicon?: string;
|
|
13
14
|
headScripts?: (Record<string, string> | string)[];
|
|
14
15
|
scripts?: (Record<string, string> | string)[];
|
|
16
|
+
mountElementId?: string;
|
|
15
17
|
esmScript?: boolean;
|
|
16
18
|
modifyHTML?: (html: string, args: {
|
|
17
19
|
path?: string;
|
|
@@ -21,4 +23,3 @@ export declare function getMarkup(opts: Omit<IOpts, 'routes'> & {
|
|
|
21
23
|
path?: string;
|
|
22
24
|
}): Promise<string>;
|
|
23
25
|
export declare function createRequestHandler(opts: IOpts): RequestHandler;
|
|
24
|
-
export {};
|
package/dist/server.js
CHANGED
|
@@ -22,7 +22,7 @@ const styles_1 = require("./styles");
|
|
|
22
22
|
function getMarkup(opts) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
// TODO: use real component
|
|
25
|
-
let markup = server_1.default.renderToString(react_1.default.createElement('div', { id: 'root' }));
|
|
25
|
+
let markup = server_1.default.renderToString(react_1.default.createElement('div', { id: opts.mountElementId || 'root' }));
|
|
26
26
|
function propsToString(opts) {
|
|
27
27
|
return Object.keys(opts.props)
|
|
28
28
|
.filter((key) => !(opts.filters || []).includes(key))
|
|
@@ -44,7 +44,7 @@ function getMarkup(opts) {
|
|
|
44
44
|
filters: ['src', 'content'],
|
|
45
45
|
});
|
|
46
46
|
return style.src
|
|
47
|
-
? `<link rel="stylesheet" ${attrs}
|
|
47
|
+
? `<link rel="stylesheet" ${attrs} href="${style.src}" />`
|
|
48
48
|
: `<style ${attrs}>${style.content}</style>`;
|
|
49
49
|
}
|
|
50
50
|
function getTagContent(opts) {
|
|
@@ -99,7 +99,7 @@ function createRequestHandler(opts) {
|
|
|
99
99
|
const routes = (0, routes_1.createServerRoutes)({
|
|
100
100
|
routesById: opts.routes,
|
|
101
101
|
});
|
|
102
|
-
const matches = (0, react_router_dom_1.matchRoutes)(routes, req.path);
|
|
102
|
+
const matches = (0, react_router_dom_1.matchRoutes)(routes, req.path, opts.base);
|
|
103
103
|
if (matches) {
|
|
104
104
|
res.set('Content-Type', 'text/html');
|
|
105
105
|
const markup = yield getMarkup(Object.assign(Object.assign({}, opts), { path: req.path }));
|
package/dist/styles.js
CHANGED
|
@@ -13,7 +13,7 @@ const RE_URL = /^(http:|https:)?\/\//;
|
|
|
13
13
|
function normalizeStyle(style) {
|
|
14
14
|
if (typeof style === 'string') {
|
|
15
15
|
const isUrl = RE_URL.test(style) ||
|
|
16
|
-
style.startsWith('/') ||
|
|
16
|
+
(style.startsWith('/') && !style.startsWith('/*')) ||
|
|
17
17
|
style.startsWith('./') ||
|
|
18
18
|
style.startsWith('../');
|
|
19
19
|
return isUrl
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/server",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
4
4
|
"description": "@umijs/server",
|
|
5
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/server#readme",
|
|
6
|
+
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/umijs/umi-next"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
5
12
|
"main": "dist/index.js",
|
|
6
13
|
"types": "dist/index.d.ts",
|
|
7
14
|
"files": [
|
|
@@ -12,26 +19,19 @@
|
|
|
12
19
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
13
20
|
"dev": "pnpm build -- --watch"
|
|
14
21
|
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/umijs/umi-next"
|
|
18
|
-
},
|
|
19
|
-
"authors": [
|
|
20
|
-
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
21
|
-
],
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
24
|
-
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/server#readme",
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
},
|
|
28
22
|
"dependencies": {
|
|
29
|
-
"history": "5.0
|
|
30
|
-
"react": "18.0.0-
|
|
31
|
-
"react-dom": "18.0.0-
|
|
32
|
-
"react-router-dom": "6.
|
|
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"
|
|
33
27
|
},
|
|
34
28
|
"devDependencies": {
|
|
35
29
|
"@types/express": "4.17.13"
|
|
36
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"authors": [
|
|
35
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
36
|
+
]
|
|
37
37
|
}
|