@umijs/server 3.5.18 → 4.0.0-beta.10
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/README.md +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/routes.d.ts +16 -0
- package/dist/routes.js +32 -0
- package/dist/scripts.d.ts +12 -0
- package/dist/scripts.js +33 -0
- package/dist/server.d.ts +24 -0
- package/dist/server.js +113 -0
- package/dist/styles.d.ts +12 -0
- package/dist/styles.js +33 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +2 -0
- package/package.json +26 -19
- package/lib/Server/Server.d.ts +0 -87
- package/lib/Server/Server.js +0 -500
- package/lib/Server/cert/cert.pem +0 -25
- package/lib/Server/cert/key.pem +0 -28
- package/lib/Server/utils.d.ts +0 -2
- package/lib/Server/utils.js +0 -108
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -41
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './server';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./server"), exports);
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IRoute, IRoutesById } from './types';
|
|
2
|
+
export declare function createServerRoutes(opts: {
|
|
3
|
+
routesById: IRoutesById;
|
|
4
|
+
parentId?: string;
|
|
5
|
+
}): {
|
|
6
|
+
id: string;
|
|
7
|
+
path: string | undefined;
|
|
8
|
+
index: boolean | undefined;
|
|
9
|
+
}[];
|
|
10
|
+
export declare function createServerRoute(opts: {
|
|
11
|
+
route: IRoute;
|
|
12
|
+
}): {
|
|
13
|
+
id: string;
|
|
14
|
+
path: string | undefined;
|
|
15
|
+
index: boolean | undefined;
|
|
16
|
+
};
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createServerRoute = exports.createServerRoutes = void 0;
|
|
4
|
+
function createServerRoutes(opts) {
|
|
5
|
+
const { routesById, parentId } = opts;
|
|
6
|
+
return Object.keys(routesById)
|
|
7
|
+
.filter((id) => routesById[id].parentId === parentId)
|
|
8
|
+
.map((id) => {
|
|
9
|
+
const route = createServerRoute({
|
|
10
|
+
route: routesById[id],
|
|
11
|
+
});
|
|
12
|
+
const children = createServerRoutes({
|
|
13
|
+
routesById,
|
|
14
|
+
parentId: route.id,
|
|
15
|
+
});
|
|
16
|
+
if (children.length > 0) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
route.children = children;
|
|
19
|
+
}
|
|
20
|
+
return route;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.createServerRoutes = createServerRoutes;
|
|
24
|
+
function createServerRoute(opts) {
|
|
25
|
+
const { route } = opts;
|
|
26
|
+
return {
|
|
27
|
+
id: route.id,
|
|
28
|
+
path: route.path,
|
|
29
|
+
index: route.index,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.createServerRoute = createServerRoute;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type IScript = string | {
|
|
2
|
+
src?: string;
|
|
3
|
+
content?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function normalizeScripts(scripts: IScript[]): {
|
|
6
|
+
src?: string | undefined;
|
|
7
|
+
content?: string | undefined;
|
|
8
|
+
}[];
|
|
9
|
+
export declare function normalizeScript(script: IScript): {
|
|
10
|
+
src?: string | undefined;
|
|
11
|
+
content?: string | undefined;
|
|
12
|
+
};
|
package/dist/scripts.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeScript = exports.normalizeScripts = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
function normalizeScripts(scripts) {
|
|
9
|
+
return scripts.map(normalizeScript);
|
|
10
|
+
}
|
|
11
|
+
exports.normalizeScripts = normalizeScripts;
|
|
12
|
+
const RE_URL = /^(http:|https:)?\/\//;
|
|
13
|
+
function normalizeScript(script) {
|
|
14
|
+
if (typeof script === 'string') {
|
|
15
|
+
const isUrl = RE_URL.test(script) ||
|
|
16
|
+
script.startsWith('/') ||
|
|
17
|
+
script.startsWith('./') ||
|
|
18
|
+
script.startsWith('../');
|
|
19
|
+
return isUrl
|
|
20
|
+
? {
|
|
21
|
+
src: script,
|
|
22
|
+
}
|
|
23
|
+
: { content: script };
|
|
24
|
+
}
|
|
25
|
+
else if (typeof script === 'object') {
|
|
26
|
+
(0, assert_1.default)(typeof script.src === 'string' || typeof script.content === 'string', `Script must have either a "src" or a "content" property.`);
|
|
27
|
+
return script;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error(`Invalid script type: ${typeof script}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.normalizeScript = normalizeScript;
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
interface IOpts {
|
|
3
|
+
routes: Record<string, {
|
|
4
|
+
path: string;
|
|
5
|
+
file: string;
|
|
6
|
+
id: string;
|
|
7
|
+
parentId?: string;
|
|
8
|
+
}>;
|
|
9
|
+
links?: Record<string, string>[];
|
|
10
|
+
metas?: Record<string, string>[];
|
|
11
|
+
styles?: (Record<string, string> | string)[];
|
|
12
|
+
favicon?: string;
|
|
13
|
+
headScripts?: (Record<string, string> | string)[];
|
|
14
|
+
scripts?: (Record<string, string> | string)[];
|
|
15
|
+
esmScript?: boolean;
|
|
16
|
+
modifyHTML?: (html: string, args: {
|
|
17
|
+
path?: string;
|
|
18
|
+
}) => Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
export declare function getMarkup(opts: Omit<IOpts, 'routes'> & {
|
|
21
|
+
path?: string;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
export declare function createRequestHandler(opts: IOpts): RequestHandler;
|
|
24
|
+
export {};
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createRequestHandler = exports.getMarkup = void 0;
|
|
16
|
+
const react_1 = __importDefault(require("react"));
|
|
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");
|
|
20
|
+
const scripts_1 = require("./scripts");
|
|
21
|
+
const styles_1 = require("./styles");
|
|
22
|
+
function getMarkup(opts) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
// TODO: use real component
|
|
25
|
+
let markup = server_1.default.renderToString(react_1.default.createElement('div', { id: 'root' }));
|
|
26
|
+
function propsToString(opts) {
|
|
27
|
+
return Object.keys(opts.props)
|
|
28
|
+
.filter((key) => !(opts.filters || []).includes(key))
|
|
29
|
+
.map((key) => `${key}=${JSON.stringify(opts.props[key])}`)
|
|
30
|
+
.join(' ');
|
|
31
|
+
}
|
|
32
|
+
function getScriptContent(script) {
|
|
33
|
+
const attrs = propsToString({
|
|
34
|
+
props: script,
|
|
35
|
+
filters: ['src', 'content'],
|
|
36
|
+
});
|
|
37
|
+
return script.src
|
|
38
|
+
? `<script${opts.esmScript ? ' type="module"' : ''} ${attrs} src="${script.src}"></script>`
|
|
39
|
+
: `<script${opts.esmScript ? ' type="module"' : ''} ${attrs}>${script.content}</script>`;
|
|
40
|
+
}
|
|
41
|
+
function getStyleContent(style) {
|
|
42
|
+
const attrs = propsToString({
|
|
43
|
+
props: style,
|
|
44
|
+
filters: ['src', 'content'],
|
|
45
|
+
});
|
|
46
|
+
return style.src
|
|
47
|
+
? `<link rel="stylesheet" ${attrs} src="${style.src}" />`
|
|
48
|
+
: `<style ${attrs}>${style.content}</style>`;
|
|
49
|
+
}
|
|
50
|
+
function getTagContent(opts) {
|
|
51
|
+
const attrs = propsToString({
|
|
52
|
+
props: opts.attrs,
|
|
53
|
+
});
|
|
54
|
+
return `<${opts.tagName} ${attrs} />`;
|
|
55
|
+
}
|
|
56
|
+
const favicon = opts.favicon
|
|
57
|
+
? `<link rel="shortcut icon" href="${opts.favicon}">`
|
|
58
|
+
: '';
|
|
59
|
+
const metas = (opts.metas || []).map((meta) => getTagContent({ attrs: meta, tagName: 'meta' }));
|
|
60
|
+
const links = (opts.links || []).map((link) => getTagContent({ attrs: link, tagName: 'link' }));
|
|
61
|
+
const styles = (0, styles_1.normalizeStyles)(opts.styles || []).map(getStyleContent);
|
|
62
|
+
const headScripts = (0, scripts_1.normalizeScripts)(opts.headScripts || []).map(getScriptContent);
|
|
63
|
+
const scripts = (0, scripts_1.normalizeScripts)(opts.scripts || []).map(getScriptContent);
|
|
64
|
+
markup = [
|
|
65
|
+
`<!DOCTYPE html>
|
|
66
|
+
<html>
|
|
67
|
+
<head>
|
|
68
|
+
<meta charset="UTF-8" />
|
|
69
|
+
<meta
|
|
70
|
+
name="viewport"
|
|
71
|
+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
|
|
72
|
+
/>
|
|
73
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />`,
|
|
74
|
+
metas.join('\n'),
|
|
75
|
+
favicon,
|
|
76
|
+
links.join('\n'),
|
|
77
|
+
styles.join('\n'),
|
|
78
|
+
headScripts.join('\n'),
|
|
79
|
+
`</head>
|
|
80
|
+
<body>`,
|
|
81
|
+
markup,
|
|
82
|
+
scripts.join('\n'),
|
|
83
|
+
`</body>
|
|
84
|
+
</html>`,
|
|
85
|
+
]
|
|
86
|
+
.filter(Boolean)
|
|
87
|
+
.join('\n');
|
|
88
|
+
if (opts.modifyHTML) {
|
|
89
|
+
markup = yield opts.modifyHTML(markup, { path: opts.path });
|
|
90
|
+
}
|
|
91
|
+
return markup;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.getMarkup = getMarkup;
|
|
95
|
+
function createRequestHandler(opts) {
|
|
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);
|
|
103
|
+
if (matches) {
|
|
104
|
+
res.set('Content-Type', 'text/html');
|
|
105
|
+
const markup = yield getMarkup(Object.assign(Object.assign({}, opts), { path: req.path }));
|
|
106
|
+
res.end(markup);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
next();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.createRequestHandler = createRequestHandler;
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type IStyle = string | {
|
|
2
|
+
src?: string;
|
|
3
|
+
content?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function normalizeStyles(scripts: IStyle[]): {
|
|
6
|
+
src?: string | undefined;
|
|
7
|
+
content?: string | undefined;
|
|
8
|
+
}[];
|
|
9
|
+
export declare function normalizeStyle(style: IStyle): {
|
|
10
|
+
src?: string | undefined;
|
|
11
|
+
content?: string | undefined;
|
|
12
|
+
};
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeStyle = exports.normalizeStyles = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
function normalizeStyles(scripts) {
|
|
9
|
+
return scripts.map(normalizeStyle);
|
|
10
|
+
}
|
|
11
|
+
exports.normalizeStyles = normalizeStyles;
|
|
12
|
+
const RE_URL = /^(http:|https:)?\/\//;
|
|
13
|
+
function normalizeStyle(style) {
|
|
14
|
+
if (typeof style === 'string') {
|
|
15
|
+
const isUrl = RE_URL.test(style) ||
|
|
16
|
+
style.startsWith('/') ||
|
|
17
|
+
style.startsWith('./') ||
|
|
18
|
+
style.startsWith('../');
|
|
19
|
+
return isUrl
|
|
20
|
+
? {
|
|
21
|
+
src: style,
|
|
22
|
+
}
|
|
23
|
+
: { content: style };
|
|
24
|
+
}
|
|
25
|
+
else if (typeof style === 'object') {
|
|
26
|
+
(0, assert_1.default)(typeof style.src === 'string' || typeof style.content === 'string', `Style must have either a "src" or a "content" property.`);
|
|
27
|
+
return style;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error(`Invalid style type: ${typeof style}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.normalizeStyle = normalizeStyle;
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.10",
|
|
4
4
|
"description": "@umijs/server",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"files": [
|
|
8
|
-
"lib"
|
|
9
|
-
],
|
|
5
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/server#readme",
|
|
6
|
+
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
10
7
|
"repository": {
|
|
11
8
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/umijs/umi"
|
|
9
|
+
"url": "https://github.com/umijs/umi-next"
|
|
13
10
|
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"umi"
|
|
16
|
-
],
|
|
17
|
-
"authors": [
|
|
18
|
-
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
19
|
-
],
|
|
20
11
|
"license": "MIT",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "pnpm tsc",
|
|
19
|
+
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
20
|
+
"dev": "pnpm build -- --watch"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"history": "5.0.1",
|
|
24
|
+
"react": "18.0.0-alpha-4298ddbc5-20211023",
|
|
25
|
+
"react-dom": "18.0.0-alpha-4298ddbc5-20211023",
|
|
26
|
+
"react-router-dom": "6.0.0-beta.8"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/express": "4.17.13"
|
|
30
|
+
},
|
|
23
31
|
"publishConfig": {
|
|
24
32
|
"access": "public"
|
|
25
33
|
},
|
|
26
|
-
"
|
|
27
|
-
"@
|
|
28
|
-
|
|
29
|
-
}
|
|
34
|
+
"authors": [
|
|
35
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
36
|
+
]
|
|
30
37
|
}
|
package/lib/Server/Server.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { CompressionOptions } from '@umijs/deps/compiled/compression';
|
|
3
|
-
import { Express, RequestHandler } from '@umijs/deps/compiled/express';
|
|
4
|
-
import { Filter as ProxyFilter, Options as ProxyOptions, RequestHandler as ProxyRequestHandler } from '@umijs/deps/compiled/http-proxy-middleware';
|
|
5
|
-
import { Connection, Server as SocketServer } from '@umijs/deps/compiled/sockjs';
|
|
6
|
-
import { ServerOptions } from '@umijs/deps/compiled/spdy';
|
|
7
|
-
import * as http from 'http';
|
|
8
|
-
interface IServerProxyConfigItem extends ProxyOptions {
|
|
9
|
-
path?: string | string[];
|
|
10
|
-
context?: string | string[] | ProxyFilter;
|
|
11
|
-
bypass?: (req: Express.Request, res: Express.Response, proxyConfig: IServerProxyConfigItem) => string | null;
|
|
12
|
-
}
|
|
13
|
-
declare type IServerProxyConfig = IServerProxyConfigItem | Record<string, IServerProxyConfigItem> | (IServerProxyConfigItem | (() => IServerProxyConfigItem))[] | null;
|
|
14
|
-
export interface IHttps extends ServerOptions {
|
|
15
|
-
}
|
|
16
|
-
export interface IServerOpts {
|
|
17
|
-
afterMiddlewares?: RequestHandler<any>[];
|
|
18
|
-
beforeMiddlewares?: RequestHandler<any>[];
|
|
19
|
-
compilerMiddleware?: RequestHandler<any> | null;
|
|
20
|
-
https?: IHttps | boolean;
|
|
21
|
-
headers?: {
|
|
22
|
-
[key: string]: string;
|
|
23
|
-
};
|
|
24
|
-
host?: string;
|
|
25
|
-
port?: number;
|
|
26
|
-
compress?: CompressionOptions | boolean;
|
|
27
|
-
proxy?: IServerProxyConfig;
|
|
28
|
-
onListening?: {
|
|
29
|
-
({ port, hostname, listeningApp, server, }: {
|
|
30
|
-
port: number;
|
|
31
|
-
hostname: string;
|
|
32
|
-
listeningApp: http.Server;
|
|
33
|
-
server: Server;
|
|
34
|
-
}): void;
|
|
35
|
-
};
|
|
36
|
-
onConnection?: (param: {
|
|
37
|
-
connection: Connection;
|
|
38
|
-
server: Server;
|
|
39
|
-
}) => void;
|
|
40
|
-
onConnectionClose?: (param: {
|
|
41
|
-
connection: Connection;
|
|
42
|
-
}) => void;
|
|
43
|
-
writeToDisk?: boolean | ((filePath: string) => boolean);
|
|
44
|
-
}
|
|
45
|
-
declare class Server {
|
|
46
|
-
app: Express;
|
|
47
|
-
opts: Required<IServerOpts>;
|
|
48
|
-
socketServer?: SocketServer;
|
|
49
|
-
listeningApp: http.Server;
|
|
50
|
-
listeninspdygApp: http.Server;
|
|
51
|
-
sockets: Connection[];
|
|
52
|
-
socketProxies: ProxyRequestHandler[];
|
|
53
|
-
constructor(opts: IServerOpts);
|
|
54
|
-
private getHttpsOptions;
|
|
55
|
-
setupFeatures(): void;
|
|
56
|
-
/**
|
|
57
|
-
* response headers
|
|
58
|
-
*/
|
|
59
|
-
setupHeaders(): void;
|
|
60
|
-
/**
|
|
61
|
-
* dev server compress to gzip assets
|
|
62
|
-
*/
|
|
63
|
-
setupCompress(): void;
|
|
64
|
-
deleteRoutes(): void;
|
|
65
|
-
/**
|
|
66
|
-
* proxy middleware for dev
|
|
67
|
-
* not coupled with build tools (like webpack, rollup, ...)
|
|
68
|
-
*/
|
|
69
|
-
setupProxy(proxyOpts?: IServerProxyConfig, isWatch?: boolean): void;
|
|
70
|
-
sockWrite({ sockets, type, data, }: {
|
|
71
|
-
sockets?: Connection[];
|
|
72
|
-
type: string;
|
|
73
|
-
data?: string | object;
|
|
74
|
-
}): void;
|
|
75
|
-
createServer(): void;
|
|
76
|
-
listen({ port, hostname, }: {
|
|
77
|
-
port?: number;
|
|
78
|
-
hostname: string;
|
|
79
|
-
}): Promise<{
|
|
80
|
-
port: number;
|
|
81
|
-
hostname: string;
|
|
82
|
-
listeningApp: http.Server;
|
|
83
|
-
server: Server;
|
|
84
|
-
}>;
|
|
85
|
-
createSocketServer(): void;
|
|
86
|
-
}
|
|
87
|
-
export default Server;
|
package/lib/Server/Server.js
DELETED
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _core() {
|
|
19
|
-
const data = require("@umijs/core");
|
|
20
|
-
|
|
21
|
-
_core = function _core() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _compression() {
|
|
29
|
-
const data = _interopRequireDefault(require("@umijs/deps/compiled/compression"));
|
|
30
|
-
|
|
31
|
-
_compression = function _compression() {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _express() {
|
|
39
|
-
const data = _interopRequireDefault(require("@umijs/deps/compiled/express"));
|
|
40
|
-
|
|
41
|
-
_express = function _express() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _httpProxyMiddleware() {
|
|
49
|
-
const data = require("@umijs/deps/compiled/http-proxy-middleware");
|
|
50
|
-
|
|
51
|
-
_httpProxyMiddleware = function _httpProxyMiddleware() {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _sockjs() {
|
|
59
|
-
const data = _interopRequireDefault(require("@umijs/deps/compiled/sockjs"));
|
|
60
|
-
|
|
61
|
-
_sockjs = function _sockjs() {
|
|
62
|
-
return data;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function _spdy() {
|
|
69
|
-
const data = _interopRequireDefault(require("@umijs/deps/compiled/spdy"));
|
|
70
|
-
|
|
71
|
-
_spdy = function _spdy() {
|
|
72
|
-
return data;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function _utils() {
|
|
79
|
-
const data = require("@umijs/utils");
|
|
80
|
-
|
|
81
|
-
_utils = function _utils() {
|
|
82
|
-
return data;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return data;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function http() {
|
|
89
|
-
const data = _interopRequireWildcard(require("http"));
|
|
90
|
-
|
|
91
|
-
http = function http() {
|
|
92
|
-
return data;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function url() {
|
|
99
|
-
const data = _interopRequireWildcard(require("url"));
|
|
100
|
-
|
|
101
|
-
url = function url() {
|
|
102
|
-
return data;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var _utils2 = require("./utils");
|
|
109
|
-
|
|
110
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
111
|
-
|
|
112
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
113
|
-
|
|
114
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
115
|
-
|
|
116
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
117
|
-
|
|
118
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
119
|
-
|
|
120
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
121
|
-
|
|
122
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
123
|
-
|
|
124
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
125
|
-
|
|
126
|
-
const logger = new (_core().Logger)('@umijs/server');
|
|
127
|
-
const debug = (0, _utils().createDebug)('umi:server:Server');
|
|
128
|
-
const defaultOpts = {
|
|
129
|
-
afterMiddlewares: [],
|
|
130
|
-
beforeMiddlewares: [],
|
|
131
|
-
compilerMiddleware: null,
|
|
132
|
-
compress: true,
|
|
133
|
-
// enable by default if add HTTP2
|
|
134
|
-
https: !!process.env.HTTP2 ? true : !!process.env.HTTPS,
|
|
135
|
-
onListening: argv => argv,
|
|
136
|
-
onConnection: () => {},
|
|
137
|
-
onConnectionClose: () => {},
|
|
138
|
-
proxy: null,
|
|
139
|
-
headers: {},
|
|
140
|
-
// not use
|
|
141
|
-
host: 'localhost',
|
|
142
|
-
port: 8000,
|
|
143
|
-
writeToDisk: false
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
class Server {
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
// Proxy sockets
|
|
150
|
-
constructor(opts) {
|
|
151
|
-
this.app = void 0;
|
|
152
|
-
this.opts = void 0;
|
|
153
|
-
this.socketServer = void 0;
|
|
154
|
-
this.listeningApp = void 0;
|
|
155
|
-
this.listeninspdygApp = void 0;
|
|
156
|
-
this.sockets = [];
|
|
157
|
-
this.socketProxies = [];
|
|
158
|
-
this.opts = _objectSpread(_objectSpread({}, defaultOpts), _utils().lodash.omitBy(opts, _utils().lodash.isUndefined));
|
|
159
|
-
this.app = (0, _express().default)();
|
|
160
|
-
this.setupFeatures();
|
|
161
|
-
this.createServer();
|
|
162
|
-
this.socketProxies.forEach(wsProxy => {
|
|
163
|
-
// subscribe to http 'upgrade'
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
this.listeningApp.on('upgrade', wsProxy.upgrade);
|
|
166
|
-
}, this);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
getHttpsOptions() {
|
|
170
|
-
if (this.opts.https) {
|
|
171
|
-
const credential = (0, _utils2.getCredentials)(this.opts); // note that options.spdy never existed. The user was able
|
|
172
|
-
// to set options.https.spdy before, though it was not in the
|
|
173
|
-
// docs. Keep options.https.spdy if the user sets it for
|
|
174
|
-
// backwards compatibility, but log a deprecation warning.
|
|
175
|
-
|
|
176
|
-
if (typeof this.opts.https === 'object' && this.opts.https.spdy) {
|
|
177
|
-
// for backwards compatibility: if options.https.spdy was passed in before,
|
|
178
|
-
// it was not altered in any way
|
|
179
|
-
logger.warn('Providing custom spdy server options is deprecated and will be removed in the next major version.');
|
|
180
|
-
return credential;
|
|
181
|
-
} else {
|
|
182
|
-
return _objectSpread({
|
|
183
|
-
spdy: {
|
|
184
|
-
protocols: ['h2', 'http/1.1']
|
|
185
|
-
}
|
|
186
|
-
}, credential);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
setupFeatures() {
|
|
194
|
-
const features = {
|
|
195
|
-
compress: () => {
|
|
196
|
-
if (this.opts.compress) {
|
|
197
|
-
this.setupCompress();
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
headers: () => {
|
|
201
|
-
if (_utils().lodash.isPlainObject(this.opts.headers)) {
|
|
202
|
-
this.setupHeaders();
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
beforeMiddlewares: () => {
|
|
206
|
-
this.opts.beforeMiddlewares.forEach(middleware => {
|
|
207
|
-
// @ts-ignore
|
|
208
|
-
this.app.use(middleware);
|
|
209
|
-
});
|
|
210
|
-
},
|
|
211
|
-
proxy: () => {
|
|
212
|
-
if (this.opts.proxy) {
|
|
213
|
-
this.setupProxy();
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
compilerMiddleware: () => {
|
|
217
|
-
if (this.opts.compilerMiddleware) {
|
|
218
|
-
// @ts-ignore
|
|
219
|
-
this.app.use(this.opts.compilerMiddleware);
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
afterMiddlewares: () => {
|
|
223
|
-
this.opts.afterMiddlewares.forEach(middleware => {
|
|
224
|
-
// @ts-ignore
|
|
225
|
-
this.app.use(middleware);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
Object.keys(features).forEach(stage => {
|
|
230
|
-
features[stage]();
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* response headers
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
setupHeaders() {
|
|
239
|
-
this.app.all('*', (req, res, next) => {
|
|
240
|
-
// eslint-disable-next-line
|
|
241
|
-
res.set(this.opts.headers);
|
|
242
|
-
next();
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* dev server compress to gzip assets
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
setupCompress() {
|
|
251
|
-
const compressOpts = _utils().lodash.isBoolean(this.opts.compress) ? {} : this.opts.compress;
|
|
252
|
-
this.app.use((0, _compression().default)(compressOpts));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
deleteRoutes() {
|
|
256
|
-
let startIndex = null;
|
|
257
|
-
let endIndex = null;
|
|
258
|
-
|
|
259
|
-
this.app._router.stack.forEach((item, index) => {
|
|
260
|
-
if (item.name === 'PROXY_START') startIndex = index;
|
|
261
|
-
if (item.name === 'PROXY_END') endIndex = index;
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
debug(`routes before changed: ${this.app._router.stack.map(item => item.name || 'undefined name').join(', ')}`);
|
|
265
|
-
|
|
266
|
-
if (startIndex !== null && endIndex !== null) {
|
|
267
|
-
this.app._router.stack.splice(startIndex, endIndex - startIndex + 1);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
debug(`routes after changed: ${this.app._router.stack.map(item => item.name || 'undefined name').join(', ')}`);
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* proxy middleware for dev
|
|
274
|
-
* not coupled with build tools (like webpack, rollup, ...)
|
|
275
|
-
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
setupProxy(proxyOpts, isWatch = false) {
|
|
279
|
-
let proxy = proxyOpts || this.opts.proxy;
|
|
280
|
-
|
|
281
|
-
if (!Array.isArray(proxy)) {
|
|
282
|
-
if (proxy && 'target' in proxy) {
|
|
283
|
-
proxy = [proxy];
|
|
284
|
-
} else {
|
|
285
|
-
proxy = Object.keys(proxy || {}).map(context => {
|
|
286
|
-
var _proxy;
|
|
287
|
-
|
|
288
|
-
let proxyOptions; // For backwards compatibility reasons.
|
|
289
|
-
|
|
290
|
-
const correctedContext = context.replace(/^\*$/, '**').replace(/\/\*$/, '');
|
|
291
|
-
|
|
292
|
-
if (typeof ((_proxy = proxy) === null || _proxy === void 0 ? void 0 : _proxy[context]) === 'string') {
|
|
293
|
-
proxyOptions = {
|
|
294
|
-
context: correctedContext,
|
|
295
|
-
target: proxy[context]
|
|
296
|
-
};
|
|
297
|
-
} else {
|
|
298
|
-
var _proxy2;
|
|
299
|
-
|
|
300
|
-
proxyOptions = _objectSpread(_objectSpread({}, ((_proxy2 = proxy) === null || _proxy2 === void 0 ? void 0 : _proxy2[context]) || {}), {}, {
|
|
301
|
-
context: correctedContext
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
proxyOptions.logLevel = proxyOptions.logLevel || 'warn';
|
|
306
|
-
return proxyOptions;
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const getProxyMiddleware = proxyConfig => {
|
|
312
|
-
const context = proxyConfig.context || proxyConfig.path; // It is possible to use the `bypass` method without a `target`.
|
|
313
|
-
// However, the proxy middleware has no use in this case, and will fail to instantiate.
|
|
314
|
-
|
|
315
|
-
if (proxyConfig.target) {
|
|
316
|
-
return (0, _httpProxyMiddleware().createProxyMiddleware)(context, _objectSpread(_objectSpread({}, proxyConfig), {}, {
|
|
317
|
-
onProxyRes(proxyRes, req, res) {
|
|
318
|
-
var _URL, _proxyConfig$onProxyR;
|
|
319
|
-
|
|
320
|
-
const target = typeof proxyConfig.target === 'object' ? url().format(proxyConfig.target) : proxyConfig.target;
|
|
321
|
-
const realUrl = ((_URL = new URL(req.url || '', target)) === null || _URL === void 0 ? void 0 : _URL.href) || '';
|
|
322
|
-
proxyRes.headers['x-real-url'] = realUrl;
|
|
323
|
-
(_proxyConfig$onProxyR = proxyConfig.onProxyRes) === null || _proxyConfig$onProxyR === void 0 ? void 0 : _proxyConfig$onProxyR.call(proxyConfig, proxyRes, req, res);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
}));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return;
|
|
330
|
-
}; // refresh proxy config
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
let startIndex = null;
|
|
334
|
-
let endIndex = null;
|
|
335
|
-
let routesLength = null; // when proxy opts change, delete before proxy middlwares
|
|
336
|
-
|
|
337
|
-
if (isWatch) {
|
|
338
|
-
this.app._router.stack.forEach((item, index) => {
|
|
339
|
-
if (item.name === 'PROXY_START') startIndex = index;
|
|
340
|
-
if (item.name === 'PROXY_END') endIndex = index;
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
if (startIndex !== null && endIndex !== null) {
|
|
344
|
-
this.app._router.stack.splice(startIndex, endIndex - startIndex + 1);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
routesLength = this.app._router.stack.length;
|
|
348
|
-
this.deleteRoutes();
|
|
349
|
-
} // log proxy middleware before
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
this.app.use(function PROXY_START(req, res, next) {
|
|
353
|
-
next();
|
|
354
|
-
});
|
|
355
|
-
proxy.forEach(proxyConfigOrCallback => {
|
|
356
|
-
let proxyMiddleware;
|
|
357
|
-
let proxyConfig = typeof proxyConfigOrCallback === 'function' ? proxyConfigOrCallback() : proxyConfigOrCallback;
|
|
358
|
-
proxyMiddleware = getProxyMiddleware(proxyConfig);
|
|
359
|
-
|
|
360
|
-
if (proxyConfig.ws && proxyMiddleware) {
|
|
361
|
-
this.socketProxies.push(proxyMiddleware);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
this.app.use((req, res, next) => {
|
|
365
|
-
if (typeof proxyConfigOrCallback === 'function') {
|
|
366
|
-
const newProxyConfig = proxyConfigOrCallback();
|
|
367
|
-
|
|
368
|
-
if (newProxyConfig !== proxyConfig) {
|
|
369
|
-
proxyConfig = newProxyConfig;
|
|
370
|
-
proxyMiddleware = getProxyMiddleware(proxyConfig);
|
|
371
|
-
}
|
|
372
|
-
} // - Check if we have a bypass function defined
|
|
373
|
-
// - In case the bypass function is defined we'll retrieve the
|
|
374
|
-
// bypassUrl from it otherwise bypassUrl would be null
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const bypassUrl = _utils().lodash.isFunction(proxyConfig.bypass) ? proxyConfig.bypass(req, res, proxyConfig) : null;
|
|
378
|
-
|
|
379
|
-
if (typeof bypassUrl === 'boolean') {
|
|
380
|
-
// skip the proxy
|
|
381
|
-
// @ts-ignore
|
|
382
|
-
req.url = null;
|
|
383
|
-
next();
|
|
384
|
-
} else if (typeof bypassUrl === 'string') {
|
|
385
|
-
// byPass to that url
|
|
386
|
-
req.url = bypassUrl;
|
|
387
|
-
next();
|
|
388
|
-
} else if (proxyMiddleware) {
|
|
389
|
-
return proxyMiddleware(req, res, next);
|
|
390
|
-
} else {
|
|
391
|
-
next();
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
this.app.use(function PROXY_END(req, res, next) {
|
|
396
|
-
next();
|
|
397
|
-
}); // log proxy middleware after
|
|
398
|
-
|
|
399
|
-
if (isWatch) {
|
|
400
|
-
const newRoutes = this.app._router.stack.splice(routesLength, this.app._router.stack.length - routesLength);
|
|
401
|
-
|
|
402
|
-
this.app._router.stack.splice(startIndex, 0, ...newRoutes);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
sockWrite({
|
|
407
|
-
sockets = this.sockets,
|
|
408
|
-
type,
|
|
409
|
-
data
|
|
410
|
-
}) {
|
|
411
|
-
sockets.forEach(socket => {
|
|
412
|
-
socket.write(JSON.stringify({
|
|
413
|
-
type,
|
|
414
|
-
data
|
|
415
|
-
}));
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
createServer() {
|
|
420
|
-
const httpsOpts = this.getHttpsOptions();
|
|
421
|
-
|
|
422
|
-
if (httpsOpts) {
|
|
423
|
-
// http2 using spdy, HTTP/2 by default when using https
|
|
424
|
-
this.listeningApp = _spdy().default.createServer(httpsOpts, this.app);
|
|
425
|
-
} else {
|
|
426
|
-
this.listeningApp = http().createServer(this.app);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
listen({
|
|
431
|
-
port = 8000,
|
|
432
|
-
hostname
|
|
433
|
-
}) {
|
|
434
|
-
var _this = this;
|
|
435
|
-
|
|
436
|
-
return _asyncToGenerator(function* () {
|
|
437
|
-
const foundPort = yield _utils().portfinder.getPortPromise({
|
|
438
|
-
port
|
|
439
|
-
});
|
|
440
|
-
return new Promise(resolve => {
|
|
441
|
-
_this.listeningApp.listen(foundPort, hostname, 5, () => {
|
|
442
|
-
_this.createSocketServer();
|
|
443
|
-
|
|
444
|
-
const ret = {
|
|
445
|
-
port: foundPort,
|
|
446
|
-
hostname,
|
|
447
|
-
listeningApp: _this.listeningApp,
|
|
448
|
-
server: _this
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
_this.opts.onListening(ret);
|
|
452
|
-
|
|
453
|
-
resolve(ret);
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
})();
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
createSocketServer() {
|
|
460
|
-
const server = _sockjs().default.createServer({
|
|
461
|
-
log: (severity, line) => {
|
|
462
|
-
if (line.includes('bound to')) return; // console.log(`${chalk.gray('[sockjs]')} ${line}`);
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
server.installHandlers(this.listeningApp, {
|
|
467
|
-
prefix: '/dev-server'
|
|
468
|
-
});
|
|
469
|
-
server.on('connection', connection => {
|
|
470
|
-
// Windows connection might be undefined
|
|
471
|
-
// https://github.com/webpack/webpack-dev-server/issues/2199
|
|
472
|
-
// https://github.com/sockjs/sockjs-node/issues/121
|
|
473
|
-
// https://github.com/meteor/meteor/pull/10891/files
|
|
474
|
-
if (!connection) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
this.opts.onConnection({
|
|
479
|
-
connection,
|
|
480
|
-
server: this
|
|
481
|
-
});
|
|
482
|
-
this.sockets.push(connection);
|
|
483
|
-
connection.on('close', () => {
|
|
484
|
-
this.opts.onConnectionClose({
|
|
485
|
-
connection
|
|
486
|
-
});
|
|
487
|
-
const index = this.sockets.indexOf(connection);
|
|
488
|
-
|
|
489
|
-
if (index >= 0) {
|
|
490
|
-
this.sockets.splice(index, 1);
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
this.socketServer = server;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
var _default = Server;
|
|
500
|
-
exports.default = _default;
|
package/lib/Server/cert/cert.pem
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
|
2
|
-
MIIETDCCArSgAwIBAgIQKxt9OXlPUkkQASISMtxezDANBgkqhkiG9w0BAQsFADBh
|
|
3
|
-
MR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExGzAZBgNVBAsMEmpjbEB5
|
|
4
|
-
Y2pjbDg2OC5sb2NhbDEiMCAGA1UEAwwZbWtjZXJ0IGpjbEB5Y2pjbDg2OC5sb2Nh
|
|
5
|
-
bDAeFw0xOTA2MDEwMDAwMDBaFw0zMDA2MDEwOTMzNTdaMEkxJzAlBgNVBAoTHm1r
|
|
6
|
-
Y2VydCBkZXZlbG9wbWVudCBjZXJ0aWZpY2F0ZTEeMBwGA1UECwwVamNsQHVtaWpz
|
|
7
|
-
LmxvY2FsICh1bWkpMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvKA/
|
|
8
|
-
Oz9az6kEZ5zSZyufpYXt5gOAnE/f8VY2hP3g7JDRCMk6w0XgkmGDJ45nY9fVVhCy
|
|
9
|
-
oqg8bIkLcLbvp69/I5O8ae0TbyS95mgBflhgsqjSkydhn7bZmAe5OdZv+JtGBjd2
|
|
10
|
-
2YDpzseK0z1VkXxgEAKYOsxszaCj6aktAhTQvER2DYGo0XaM62SOQNL4qLn97Zrg
|
|
11
|
-
+g8GSjS/Cg/vb+k42tCghOm0Ks26CDBl92Dwl5modEkfzewrjC2WNletiZupsX6p
|
|
12
|
-
rnRDBcGYHl+S/+D/iHCSu83IkxoorsIigGlSah/nVfetsKHBTXFXnSxL86T9MA1R
|
|
13
|
-
5ZcXoVv1cWZNiiMMawIDAQABo4GXMIGUMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE
|
|
14
|
-
DDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMB8GA1UdIwQYMBaAFFRTg3QdwqVq
|
|
15
|
-
CLRjdLfglrJZqTrzMD4GA1UdEQQ3MDWCCWxvY2FsaG9zdIIQbG9jYWwuYWxpcGF5
|
|
16
|
-
Lm5ldIcEfwAAAYcQAAAAAAAAAAAAAAAAAAAAATANBgkqhkiG9w0BAQsFAAOCAYEA
|
|
17
|
-
lFgca57CNAoaq8MC6bTZo10FC/LDTnUh/p20w5uCp8iSKGtVM+HvulrWXwUGRkUl
|
|
18
|
-
jnukYeMwl4tONzwHeUV1oVT8DATFLAFIHE4ikGDM7V+Ximxv5yQQ9hD8fzeOWdYO
|
|
19
|
-
SKA5eDjd+ut+HiSfItqgM+8t1RxPxsYlGeOMp65cKt1NaIdRxQHwESGba6H0sez7
|
|
20
|
-
p5Eu95pXp/BUy7lnvqudXgfTAUpSzxpSG+49hzMKuN/CAZyFNp52qDDHpRtuxHns
|
|
21
|
-
q0pjGHBOC2aYc1eXNgn2g0wMDp3+BYh9yjoWNkMKqY7hpcB9PY5zw0u8R0wG8z+n
|
|
22
|
-
d915bZT3FKjx5sxmDmVaDNdARwi9ExqFvIs+hje1IUrszR7pnT7EUcUOhWNbKKkf
|
|
23
|
-
jRH3sy+TyA+TsYm1AAcnnY/Ne/Ce4OcMGcYwjb1L/gu/PWoup4f/GIziEw8cbPti
|
|
24
|
-
1+Exm+AOSjcSspPPfQmpHqupNaDJSjo6xYX3wn3oIb34WvH8INL3liiVedn+LTy4
|
|
25
|
-
-----END CERTIFICATE-----
|
package/lib/Server/cert/key.pem
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
-----BEGIN PRIVATE KEY-----
|
|
2
|
-
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8oD87P1rPqQRn
|
|
3
|
-
nNJnK5+lhe3mA4CcT9/xVjaE/eDskNEIyTrDReCSYYMnjmdj19VWELKiqDxsiQtw
|
|
4
|
-
tu+nr38jk7xp7RNvJL3maAF+WGCyqNKTJ2GfttmYB7k51m/4m0YGN3bZgOnOx4rT
|
|
5
|
-
PVWRfGAQApg6zGzNoKPpqS0CFNC8RHYNgajRdozrZI5A0viouf3tmuD6DwZKNL8K
|
|
6
|
-
D+9v6Tja0KCE6bQqzboIMGX3YPCXmah0SR/N7CuMLZY2V62Jm6mxfqmudEMFwZge
|
|
7
|
-
X5L/4P+IcJK7zciTGiiuwiKAaVJqH+dV962wocFNcVedLEvzpP0wDVHllxehW/Vx
|
|
8
|
-
Zk2KIwxrAgMBAAECggEAUdiitz2dVN/85kyYy2WVZ0g+2wCIDMtn25tSGtDiiSOp
|
|
9
|
-
YEuYsOSgNkQTmdVjrWIY0rh6GrQvS9UHXsgyIyu2WiSfq8LQHPjvYYudokoM41j3
|
|
10
|
-
zhxXcurvbdVkHOGcQl51uvrUGjqiuTPCXDiP6YnzUN8fWNwdFfhvR1M+EVog3J+F
|
|
11
|
-
RpSavm+SCOkyqCBWgQDb/p59kvlISJuDXKr3tV5HaKVKYfDBQLvuiZBweDwXjxop
|
|
12
|
-
z2Srs2GEmJPuKXU32deqNg7KgPvd6ADxb+GXhrGVBaj7dxi77E8nHL/aGutVE4ON
|
|
13
|
-
VqMwdWoRPkEPU33rF+CCxHqHJFcNS+62ozzeUYGlaQKBgQDR2mPnjthIgMkX+cw5
|
|
14
|
-
ROSadd5gZtQFXAzjAv685k+Xqm2IGk2Z2d5VydHO7cKwVLTB6cEJ+CbLZ1kIS6yV
|
|
15
|
-
GxBHaZ+LQxGkt4QD9IBSnL9Cxe7uvo+bpvV3eXbANG0tNl482RctS/u+g+OGSu05
|
|
16
|
-
6KIIlYag5hcMjr7ozuhv8LVytwKBgQDmGuIKFHXXqeRJNW+QvJfwQFKNQViqASlY
|
|
17
|
-
W4Y5guS6s85inJ3bRKwYtZsczne2uwYqQHlPw8X4TQMXApM+04mJtqwrYDpcX6Ad
|
|
18
|
-
VYPmo+J/k917QwlN8VP4AzlDdz8PU+zenmWgpKaG8GMtYia9qCIbWY/+hwwBk0sG
|
|
19
|
-
FNpguWnv7QKBgFSGT2ksSwdhAB5tGgoTKrTgNvLDWDDUc8hYI3y4k2R2W+nPFmSa
|
|
20
|
-
sYgCY0Si1aEqbSgR3BQE5LNW7DCAMoJYRUVOUNnJ6Ohclor1R15/DjZ5/RQioztB
|
|
21
|
-
k2tM/DzMoRDt7iU6F7DCAyMoglNMCKMjhWhJudFC/BOtx02EUXENFjifAoGAD966
|
|
22
|
-
yEcw+XbWL9Zno2vebsuA5g0juFXsLBPj5gOJEvdjvJlgqcbKt8mOsSXsS8YKXs+j
|
|
23
|
-
jkTKWp21INkknqioS781kKhKXiSaPmuvdTDIZlQkamPtOFr0l55hTK3kw4HeTFxQ
|
|
24
|
-
VgwFEDl0HaUvVtVJxOkgbUWTJmiqO/kkNpeTHuECgYEAtD4dRK3w65d9BWHqgeOV
|
|
25
|
-
IVSDeYjA6gNuC3tuGzk9bA70U0X/T8+EQMuKNvRZC61/JzAlzEH1oGIw8md8Ki86
|
|
26
|
-
aRT96Gce7Q0FA3SaQ+h+w+kgsJG/aly3IThaJh/mx6HN7Xry6BFO1vlYlgdlm/1G
|
|
27
|
-
iKX/ppCt7bJYqfrptWs42u4=
|
|
28
|
-
-----END PRIVATE KEY-----
|
package/lib/Server/utils.d.ts
DELETED
package/lib/Server/utils.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getCredentials = void 0;
|
|
7
|
-
|
|
8
|
-
function _react() {
|
|
9
|
-
const data = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
_react = function _react() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _core() {
|
|
19
|
-
const data = require("@umijs/core");
|
|
20
|
-
|
|
21
|
-
_core = function _core() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _immer() {
|
|
29
|
-
const data = _interopRequireDefault(require("@umijs/deps/compiled/immer"));
|
|
30
|
-
|
|
31
|
-
_immer = function _immer() {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function fs() {
|
|
39
|
-
const data = _interopRequireWildcard(require("fs"));
|
|
40
|
-
|
|
41
|
-
fs = function fs() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _path() {
|
|
49
|
-
const data = require("path");
|
|
50
|
-
|
|
51
|
-
_path = function _path() {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
59
|
-
|
|
60
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
61
|
-
|
|
62
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
63
|
-
|
|
64
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
65
|
-
|
|
66
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
67
|
-
|
|
68
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
69
|
-
|
|
70
|
-
const logger = new (_core().Logger)('@umijs/server:utils');
|
|
71
|
-
|
|
72
|
-
const getCredentials = opts => {
|
|
73
|
-
const https = opts.https;
|
|
74
|
-
const defautlServerOptions = {
|
|
75
|
-
key: (0, _path().join)(__dirname, 'cert', 'key.pem'),
|
|
76
|
-
cert: (0, _path().join)(__dirname, 'cert', 'cert.pem')
|
|
77
|
-
}; // custom cert using https: { key: '', cert: '' }
|
|
78
|
-
|
|
79
|
-
const serverOptions = https === true ? defautlServerOptions : https;
|
|
80
|
-
|
|
81
|
-
if (!(serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.key) || !(serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.cert)) {
|
|
82
|
-
const err = new Error(`Both options.https.key and options.https.cert are required.`);
|
|
83
|
-
logger.error(err);
|
|
84
|
-
throw err;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const credentials = (0, _immer().default)(_objectSpread(_objectSpread({}, serverOptions), {}, {
|
|
88
|
-
key: fs().readFileSync(serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.key, 'utf-8'),
|
|
89
|
-
cert: fs().readFileSync(serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.cert, 'utf-8')
|
|
90
|
-
}), draft => {
|
|
91
|
-
if (typeof serverOptions === 'object' && serverOptions.ca) {
|
|
92
|
-
const newServerOptions = (0, _immer().default)(serverOptions, optDraft => {
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
optDraft.ca = !Array.isArray(optDraft.ca) ? [optDraft.ca] : optDraft.ca;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (Array.isArray(newServerOptions.ca)) {
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
draft.ca = newServerOptions.ca.map(function (ca) {
|
|
100
|
-
return fs().readFileSync(ca, 'utf-8');
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return credentials;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
exports.getCredentials = getCredentials;
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "createProxyMiddleware", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _httpProxyMiddleware().createProxyMiddleware;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "Server", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _Server.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
function _react() {
|
|
20
|
-
const data = _interopRequireDefault(require("react"));
|
|
21
|
-
|
|
22
|
-
_react = function _react() {
|
|
23
|
-
return data;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function _httpProxyMiddleware() {
|
|
30
|
-
const data = require("@umijs/deps/compiled/http-proxy-middleware");
|
|
31
|
-
|
|
32
|
-
_httpProxyMiddleware = function _httpProxyMiddleware() {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var _Server = _interopRequireDefault(require("./Server/Server"));
|
|
40
|
-
|
|
41
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|