@modern-js/server 1.1.1-canary.3 → 1.1.3-beta.0
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/CHANGELOG.md +28 -0
- package/dist/js/modern/libs/hook-api/route.js +37 -0
- package/dist/js/modern/libs/{hook-api.js → hook-api/template.js} +0 -0
- package/dist/js/modern/libs/route/index.js +4 -0
- package/dist/js/modern/libs/route/matcher.js +5 -1
- package/dist/js/modern/libs/serve-file.js +23 -25
- package/dist/js/modern/server/{web-server.js → dev-server/dev-server-split.js} +9 -7
- package/dist/js/modern/server/{dev-server.js → dev-server/dev-server.js} +41 -22
- package/dist/js/modern/server/dev-server/index.js +2 -0
- package/dist/js/modern/server/index.js +61 -62
- package/dist/js/modern/server/{api-server.js → modern-server-split.js} +6 -10
- package/dist/js/modern/server/modern-server.js +78 -25
- package/dist/js/modern/utils.js +2 -2
- package/dist/js/node/libs/hook-api/route.js +46 -0
- package/dist/js/node/libs/{hook-api.js → hook-api/template.js} +0 -0
- package/dist/js/node/libs/route/index.js +4 -0
- package/dist/js/node/libs/route/matcher.js +5 -1
- package/dist/js/node/libs/serve-file.js +25 -26
- package/dist/js/node/server/{api-server.js → dev-server/dev-server-split.js} +7 -12
- package/dist/js/node/server/{dev-server.js → dev-server/dev-server.js} +42 -21
- package/dist/js/node/server/dev-server/index.js +27 -0
- package/dist/js/node/server/index.js +67 -63
- package/dist/js/node/server/{web-server.js → modern-server-split.js} +10 -9
- package/dist/js/node/server/modern-server.js +80 -25
- package/dist/js/node/utils.js +2 -2
- package/dist/types/libs/hook-api/route.d.ts +13 -0
- package/dist/types/libs/{hook-api.d.ts → hook-api/template.d.ts} +0 -0
- package/dist/types/libs/route/index.d.ts +1 -0
- package/dist/types/libs/route/matcher.d.ts +1 -0
- package/dist/types/libs/serve-file.d.ts +1 -1
- package/dist/types/server/{api-server.d.ts → dev-server/dev-server-split.d.ts} +7 -8
- package/dist/types/server/{dev-server.d.ts → dev-server/dev-server.d.ts} +6 -5
- package/dist/types/server/dev-server/index.d.ts +2 -0
- package/dist/types/server/index.d.ts +3 -1
- package/dist/types/server/{web-server.d.ts → modern-server-split.d.ts} +5 -4
- package/dist/types/server/modern-server.d.ts +7 -5
- package/dist/types/utils.d.ts +1 -1
- package/package.json +10 -10
- package/src/libs/hook-api/route.ts +38 -0
- package/src/libs/{hook-api.ts → hook-api/template.ts} +0 -0
- package/src/libs/route/index.ts +4 -0
- package/src/libs/route/matcher.ts +5 -1
- package/src/libs/serve-file.ts +16 -20
- package/src/server/{api-server.ts → dev-server/dev-server-split.ts} +9 -11
- package/src/server/{dev-server.ts → dev-server/dev-server.ts} +56 -23
- package/src/server/dev-server/index.ts +2 -0
- package/src/server/index.ts +69 -46
- package/src/server/{web-server.ts → modern-server-split.ts} +12 -10
- package/src/server/modern-server.ts +87 -40
- package/src/utils.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0fa83663: support more .env files
|
|
8
|
+
- f594fbc8: fix apple icon and favicon support
|
|
9
|
+
- d1fde77a: fix public/ file in windows
|
|
10
|
+
- Updated dependencies [6f7fe574]
|
|
11
|
+
- Updated dependencies [b011e0c5]
|
|
12
|
+
- Updated dependencies [0fa83663]
|
|
13
|
+
- Updated dependencies [f594fbc8]
|
|
14
|
+
- @modern-js/core@1.1.2
|
|
15
|
+
- @modern-js/server-utils@1.1.1
|
|
16
|
+
- @modern-js/bff-utils@1.1.1
|
|
17
|
+
- @modern-js/hmr-client@1.1.1
|
|
18
|
+
- @modern-js/server-plugin@1.1.1
|
|
19
|
+
- @modern-js/utils@1.1.2
|
|
20
|
+
|
|
21
|
+
## 1.1.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- c0fc0700: feat: support deploy plugin
|
|
26
|
+
- Updated dependencies [687c92c7]
|
|
27
|
+
- Updated dependencies [c0fc0700]
|
|
28
|
+
- @modern-js/core@1.1.1
|
|
29
|
+
- @modern-js/utils@1.1.1
|
|
30
|
+
|
|
3
31
|
## 1.1.0
|
|
4
32
|
|
|
5
33
|
### Minor Changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class RouteAPI {
|
|
2
|
+
constructor(matched, router) {
|
|
3
|
+
this.router = void 0;
|
|
4
|
+
this.current = void 0;
|
|
5
|
+
this.current = matched;
|
|
6
|
+
this.router = router;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
cur() {
|
|
10
|
+
return this.current.generate();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get(entryName) {
|
|
14
|
+
const {
|
|
15
|
+
router
|
|
16
|
+
} = this;
|
|
17
|
+
const matched = router.matchEntry(entryName);
|
|
18
|
+
return matched ? matched.generate() : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
use(entryName) {
|
|
22
|
+
const {
|
|
23
|
+
router
|
|
24
|
+
} = this;
|
|
25
|
+
const matched = router.matchEntry(entryName);
|
|
26
|
+
|
|
27
|
+
if (matched) {
|
|
28
|
+
this.current = matched;
|
|
29
|
+
return true;
|
|
30
|
+
} else {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const createRouteAPI = (matched, router) => new RouteAPI(matched, router);
|
|
File without changes
|
|
@@ -56,6 +56,10 @@ export class RouteMatchManager {
|
|
|
56
56
|
return best;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
matchEntry(entryname) {
|
|
60
|
+
return this.matchers.find(matcher => matcher.matchEntry(entryname));
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
getBundles() {
|
|
60
64
|
const bundles = this.specs.filter(route => route.isSSR).map(route => route.bundle);
|
|
61
65
|
return bundles;
|
|
@@ -2,7 +2,7 @@ import { removeTailSlash } from '@modern-js/utils';
|
|
|
2
2
|
import { match, pathToRegexp } from 'path-to-regexp';
|
|
3
3
|
import { ModernRoute } from "./route"; // eslint-disable-next-line no-useless-escape
|
|
4
4
|
|
|
5
|
-
const regCharsDetector = /[^a-zA-Z\-_0-9
|
|
5
|
+
const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
|
|
6
6
|
export class RouteMatcher {
|
|
7
7
|
constructor(spec) {
|
|
8
8
|
this.spec = void 0;
|
|
@@ -57,6 +57,10 @@ export class RouteMatcher {
|
|
|
57
57
|
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
matchEntry(entryName) {
|
|
63
|
+
return this.spec.entryName === entryName;
|
|
60
64
|
} // compiler urlPath to regexp if necessary
|
|
61
65
|
|
|
62
66
|
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
// Todo 看看是不是能 fork 一份,即使命中也返回
|
|
2
2
|
import serve from 'serve-static';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { isString, isRegExp } from '@modern-js/utils';
|
|
4
|
+
export const createStaticFileHandler = rules => // eslint-disable-next-line consistent-return
|
|
5
|
+
async (context, next) => {
|
|
6
|
+
const {
|
|
7
|
+
url: requestUrl,
|
|
8
|
+
req,
|
|
9
|
+
res
|
|
10
|
+
} = context;
|
|
11
|
+
const hitRule = rules.find(item => {
|
|
12
|
+
if (isString(item.path) && requestUrl.startsWith(item.path)) {
|
|
13
|
+
return true;
|
|
14
|
+
} else if (isRegExp(item.path) && item.path.test(requestUrl)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
url: requestUrl,
|
|
12
|
-
req,
|
|
13
|
-
res
|
|
14
|
-
} = context;
|
|
15
|
-
const hit = Object.keys(middlewares).find(u => requestUrl.startsWith(u));
|
|
18
|
+
return false;
|
|
19
|
+
});
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
next();
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
return next();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
21
|
+
if (hitRule) {
|
|
22
|
+
serve(hitRule.target)(req, res, () => {
|
|
23
|
+
next();
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
return next();
|
|
27
|
+
}
|
|
30
28
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ModernDevServer } from "./dev-server";
|
|
2
|
-
|
|
3
|
-
export class WebModernServer extends ModernServer {
|
|
2
|
+
export class WebModernDevServer extends ModernDevServer {
|
|
4
3
|
prepareAPIHandler(_m, _) {
|
|
5
4
|
return null;
|
|
6
5
|
}
|
|
@@ -14,17 +13,20 @@ export class WebModernServer extends ModernServer {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
}
|
|
17
|
-
export class
|
|
18
|
-
|
|
16
|
+
export class APIModernDevServer extends ModernDevServer {
|
|
17
|
+
prepareWebHandler(_) {
|
|
19
18
|
return null;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
async
|
|
23
|
-
return super.
|
|
21
|
+
async prepareAPIHandler(mode, extension) {
|
|
22
|
+
return super.prepareAPIHandler(mode, extension);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
filterRoutes(routes) {
|
|
27
|
-
return routes.filter(route => route.
|
|
26
|
+
return routes.filter(route => route.isApi);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async preServerInit() {// noop
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import { createServer } from 'http';
|
|
1
2
|
import path from 'path';
|
|
2
|
-
import {
|
|
3
|
+
import { createServer as createHttpsServer } from 'https';
|
|
4
|
+
import { API_DIR, HMR_SOCK_PATH, SERVER_DIR, SHARED_DIR } from '@modern-js/utils';
|
|
3
5
|
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { AGGRED_DIR } from "
|
|
6
|
+
import { ModernServer } from "../modern-server";
|
|
7
|
+
import { createMockHandler } from "../../dev-tools/mock";
|
|
8
|
+
import { createProxyHandler } from "../../libs/proxy";
|
|
9
|
+
import SocketServer from "../../dev-tools/socket-server";
|
|
10
|
+
import DevServerPlugin from "../../dev-tools/dev-server-plugin";
|
|
11
|
+
import { createLaunchEditorHandler } from "../../dev-tools/launch-editor";
|
|
12
|
+
import { enableRegister } from "../../dev-tools/babel/register";
|
|
13
|
+
import * as reader from "../../libs/render/reader";
|
|
14
|
+
import Watcher from "../../dev-tools/watcher";
|
|
15
|
+
import { AGGRED_DIR } from "../../constants";
|
|
14
16
|
const DEFAULT_DEV_OPTIONS = {
|
|
15
17
|
client: {
|
|
16
18
|
port: '8080',
|
|
@@ -27,8 +29,8 @@ const DEFAULT_DEV_OPTIONS = {
|
|
|
27
29
|
liveReload: true
|
|
28
30
|
};
|
|
29
31
|
export class ModernDevServer extends ModernServer {
|
|
30
|
-
constructor(options
|
|
31
|
-
super(options
|
|
32
|
+
constructor(options) {
|
|
33
|
+
super(options); // set webpack compiler
|
|
32
34
|
|
|
33
35
|
this.devProxyHandler = null;
|
|
34
36
|
this.mockHandler = null;
|
|
@@ -40,18 +42,18 @@ export class ModernDevServer extends ModernServer {
|
|
|
40
42
|
this.compiler = options.compiler; // set dev server options, like webpack-dev-server
|
|
41
43
|
|
|
42
44
|
this.dev = typeof options.dev === 'boolean' ? DEFAULT_DEV_OPTIONS : options.dev;
|
|
45
|
+
enableRegister(this.pwd, this.conf);
|
|
43
46
|
} // Complete the preparation of services
|
|
44
47
|
|
|
45
48
|
|
|
46
|
-
async init() {
|
|
49
|
+
async init(runner) {
|
|
47
50
|
var _conf$tools, _conf$tools$devServer;
|
|
48
51
|
|
|
49
52
|
const {
|
|
50
53
|
conf,
|
|
51
54
|
pwd,
|
|
52
55
|
compiler
|
|
53
|
-
} = this;
|
|
54
|
-
enableRegister(pwd, conf); // mock handler
|
|
56
|
+
} = this; // mock handler
|
|
55
57
|
|
|
56
58
|
this.mockHandler = createMockHandler({
|
|
57
59
|
pwd
|
|
@@ -86,7 +88,7 @@ export class ModernDevServer extends ModernServer {
|
|
|
86
88
|
this.addHandler(devMiddlewareHandler);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
await super.init(); // watch mock/ server/ api/ dir file change
|
|
91
|
+
await super.init(runner); // watch mock/ server/ api/ dir file change
|
|
90
92
|
|
|
91
93
|
this.startWatcher();
|
|
92
94
|
}
|
|
@@ -97,6 +99,7 @@ export class ModernDevServer extends ModernServer {
|
|
|
97
99
|
this.cleanSSRCache(); // reset static file
|
|
98
100
|
|
|
99
101
|
reader.updateFile();
|
|
102
|
+
this.runner.reset();
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
onListening(app) {
|
|
@@ -113,6 +116,24 @@ export class ModernDevServer extends ModernServer {
|
|
|
113
116
|
resolve();
|
|
114
117
|
});
|
|
115
118
|
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async createHTTPServer(handler) {
|
|
122
|
+
const {
|
|
123
|
+
dev
|
|
124
|
+
} = this;
|
|
125
|
+
const devHttpsOption = typeof dev === 'object' && dev.https;
|
|
126
|
+
|
|
127
|
+
if (devHttpsOption) {
|
|
128
|
+
const {
|
|
129
|
+
genHttpsOptions
|
|
130
|
+
} = require("../../dev-tools/https");
|
|
131
|
+
|
|
132
|
+
const httpsOptions = await genHttpsOptions(devHttpsOption);
|
|
133
|
+
return createHttpsServer(httpsOptions, handler);
|
|
134
|
+
} else {
|
|
135
|
+
return createServer(handler);
|
|
136
|
+
}
|
|
116
137
|
} // set up plugin to each compiler
|
|
117
138
|
// register hooks for each compilation, update socket stats if recompiled
|
|
118
139
|
// start dev middleware
|
|
@@ -207,18 +228,16 @@ export class ModernDevServer extends ModernServer {
|
|
|
207
228
|
pwd
|
|
208
229
|
} = this;
|
|
209
230
|
const {
|
|
210
|
-
mock
|
|
211
|
-
server,
|
|
212
|
-
api,
|
|
213
|
-
shared
|
|
231
|
+
mock
|
|
214
232
|
} = AGGRED_DIR;
|
|
215
|
-
const defaultWatched = [`${pwd}/${mock}/**/*`, `${pwd}/${
|
|
233
|
+
const defaultWatched = [`${pwd}/${mock}/**/*`, `${pwd}/${SERVER_DIR}/**/*`, `${pwd}/${API_DIR}/**/*`, `${pwd}/${SHARED_DIR}/**/*`];
|
|
216
234
|
const watcher = new Watcher();
|
|
217
235
|
watcher.createDepTree(); // 监听文件变动,如果有变动则给 client,也就是 start 启动的插件发消息
|
|
218
236
|
|
|
219
237
|
watcher.listen(defaultWatched, filepath => {
|
|
220
238
|
watcher.updateDepTree();
|
|
221
239
|
watcher.cleanDepCache(filepath);
|
|
240
|
+
this.runner.reset();
|
|
222
241
|
|
|
223
242
|
if (filepath.startsWith(`${pwd}/${mock}`)) {
|
|
224
243
|
this.mockHandler = createMockHandler({
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
import path from 'path';
|
|
3
8
|
import { serverManager } from '@modern-js/server-plugin';
|
|
4
9
|
import { logger as defaultLogger } from '@modern-js/utils';
|
|
10
|
+
import { AppContext, initAppContext, initAppDir, loadUserConfig } from '@modern-js/core';
|
|
5
11
|
import { ModernServer } from "./modern-server";
|
|
12
|
+
import { APIModernServer, WebModernServer } from "./modern-server-split";
|
|
6
13
|
import { measure as defaultMeasure } from "../libs/measure";
|
|
7
14
|
export class Server {
|
|
8
15
|
constructor(options) {
|
|
9
|
-
var _options$plugins;
|
|
10
|
-
|
|
11
16
|
this.options = void 0;
|
|
12
17
|
this.server = void 0;
|
|
13
18
|
this.app = void 0;
|
|
14
19
|
this.runner = void 0;
|
|
15
20
|
this.options = options;
|
|
16
|
-
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
17
|
-
serverManager.usePlugin(p);
|
|
18
|
-
});
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
getRequestHandler() {
|
|
@@ -33,40 +35,20 @@ export class Server {
|
|
|
33
35
|
const {
|
|
34
36
|
options
|
|
35
37
|
} = this;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
logger,
|
|
39
|
-
measure
|
|
40
|
-
} = await this.runner.create({
|
|
41
|
-
loggerOptions: options.logger,
|
|
42
|
-
measureOptions: options.measure
|
|
43
|
-
}, {
|
|
44
|
-
onLast: () => ({})
|
|
45
|
-
});
|
|
46
|
-
options.logger = options.logger || logger || defaultLogger;
|
|
47
|
-
options.measure = options.measure || measure || defaultMeasure;
|
|
38
|
+
options.logger = options.logger || defaultLogger;
|
|
39
|
+
options.measure = options.measure || defaultMeasure; // initialize server
|
|
48
40
|
|
|
49
41
|
if (options.dev) {
|
|
50
|
-
this.server = this.createDevServer();
|
|
51
|
-
|
|
52
|
-
const devHttpsOption = typeof options.dev === 'object' && options.dev.https;
|
|
53
|
-
|
|
54
|
-
if (devHttpsOption) {
|
|
55
|
-
const {
|
|
56
|
-
genHttpsOptions
|
|
57
|
-
} = require("../dev-tools/https");
|
|
58
|
-
|
|
59
|
-
const httpsOptions = await genHttpsOptions(devHttpsOption);
|
|
60
|
-
this.app = createHttpsServer(httpsOptions, this.getRequestHandler());
|
|
61
|
-
} else {
|
|
62
|
-
this.app = createServer(this.getRequestHandler());
|
|
63
|
-
}
|
|
42
|
+
this.server = this.createDevServer();
|
|
64
43
|
} else {
|
|
65
44
|
this.server = this.createProdServer();
|
|
66
|
-
|
|
67
|
-
}
|
|
45
|
+
} // check if https is configured when start dev server
|
|
68
46
|
|
|
69
|
-
|
|
47
|
+
|
|
48
|
+
this.app = await this.server.createHTTPServer(this.getRequestHandler());
|
|
49
|
+
this.runner = await this.createHookRunner(); // runner can only be used after server init
|
|
50
|
+
|
|
51
|
+
await this.server.init(this.runner);
|
|
70
52
|
return this;
|
|
71
53
|
}
|
|
72
54
|
|
|
@@ -97,19 +79,11 @@ export class Server {
|
|
|
97
79
|
} = this;
|
|
98
80
|
|
|
99
81
|
if (options.apiOnly) {
|
|
100
|
-
|
|
101
|
-
APIModernServer
|
|
102
|
-
} = require("./api-server");
|
|
103
|
-
|
|
104
|
-
return new APIModernServer(options, this.runner);
|
|
82
|
+
return new APIModernServer(options);
|
|
105
83
|
} else if (options.webOnly) {
|
|
106
|
-
|
|
107
|
-
WebModernServer
|
|
108
|
-
} = require("./web-server");
|
|
109
|
-
|
|
110
|
-
return new WebModernServer(options, this.runner);
|
|
84
|
+
return new WebModernServer(options);
|
|
111
85
|
} else {
|
|
112
|
-
return new ModernServer(options
|
|
86
|
+
return new ModernServer(options);
|
|
113
87
|
}
|
|
114
88
|
}
|
|
115
89
|
|
|
@@ -118,25 +92,50 @@ export class Server {
|
|
|
118
92
|
options
|
|
119
93
|
} = this;
|
|
120
94
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
95
|
+
const {
|
|
96
|
+
APIModernDevServer,
|
|
97
|
+
WebModernDevServer,
|
|
98
|
+
ModernDevServer
|
|
99
|
+
} = require("./dev-server");
|
|
125
100
|
|
|
126
|
-
|
|
101
|
+
if (options.apiOnly) {
|
|
102
|
+
return new APIModernDevServer(options);
|
|
127
103
|
} else if (options.webOnly) {
|
|
128
|
-
|
|
129
|
-
WebModernDevServer
|
|
130
|
-
} = require("./web-server");
|
|
131
|
-
|
|
132
|
-
return new WebModernDevServer(options, this.runner);
|
|
104
|
+
return new WebModernDevServer(options);
|
|
133
105
|
} else {
|
|
134
|
-
|
|
135
|
-
ModernDevServer
|
|
136
|
-
} = require("./dev-server");
|
|
137
|
-
|
|
138
|
-
return new ModernDevServer(options, this.runner);
|
|
106
|
+
return new ModernDevServer(options);
|
|
139
107
|
}
|
|
140
108
|
}
|
|
141
109
|
|
|
110
|
+
async createHookRunner() {
|
|
111
|
+
var _options$plugins;
|
|
112
|
+
|
|
113
|
+
const {
|
|
114
|
+
options
|
|
115
|
+
} = this;
|
|
116
|
+
const appContext = await this.initAppContext();
|
|
117
|
+
serverManager.run(() => {
|
|
118
|
+
AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
119
|
+
distDirectory: path.join(options.pwd, options.config.output.path || 'dist')
|
|
120
|
+
}));
|
|
121
|
+
});
|
|
122
|
+
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
123
|
+
serverManager.usePlugin(p);
|
|
124
|
+
});
|
|
125
|
+
return serverManager.init({});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async initAppContext() {
|
|
129
|
+
var _this$options$plugins;
|
|
130
|
+
|
|
131
|
+
const appDirectory = await initAppDir();
|
|
132
|
+
const loaded = await loadUserConfig(appDirectory);
|
|
133
|
+
const plugins = (_this$options$plugins = this.options.plugins) === null || _this$options$plugins === void 0 ? void 0 : _this$options$plugins.map(p => ({
|
|
134
|
+
server: p,
|
|
135
|
+
cli: undefined
|
|
136
|
+
}));
|
|
137
|
+
const appContext = initAppContext(appDirectory, plugins || [], loaded.filePath);
|
|
138
|
+
return appContext;
|
|
139
|
+
}
|
|
140
|
+
|
|
142
141
|
}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import { ModernDevServer } from "./dev-server";
|
|
2
1
|
import { ModernServer } from "./modern-server";
|
|
3
|
-
export class
|
|
4
|
-
|
|
2
|
+
export class WebModernServer extends ModernServer {
|
|
3
|
+
prepareAPIHandler(_m, _) {
|
|
5
4
|
return null;
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
async
|
|
9
|
-
return super.
|
|
7
|
+
async prepareWebHandler(extension) {
|
|
8
|
+
return super.prepareWebHandler(extension);
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
filterRoutes(routes) {
|
|
13
|
-
return routes.filter(route => route.
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async preServerInit() {// noop
|
|
12
|
+
return routes.filter(route => route.entryName);
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
}
|
|
20
|
-
export class
|
|
16
|
+
export class APIModernServer extends ModernServer {
|
|
21
17
|
prepareWebHandler(_) {
|
|
22
18
|
return null;
|
|
23
19
|
}
|