@shuvi/service 1.0.44 → 1.0.45
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/lib/server/middlewares/setupAppConfigMiddleware.d.ts +3 -0
- package/lib/server/middlewares/setupAppConfigMiddleware.js +25 -0
- package/lib/server/plugin.d.ts +12 -0
- package/lib/server/plugin.js +10 -2
- package/lib/server/shuviDevServer.js +2 -0
- package/lib/server/shuviProdServer.js +2 -0
- package/package.json +9 -9
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setupAppConfigMiddleware = void 0;
|
|
13
|
+
const setupAppConfigMiddleware = (context) => {
|
|
14
|
+
return (req, _res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const appConfig = context.serverPluginRunner.getAppConfig({ req });
|
|
16
|
+
if (appConfig) {
|
|
17
|
+
if (typeof appConfig.router.basename !== 'string') {
|
|
18
|
+
throw new Error('[ServerPlugin Hook getAppConfig] appConfig.router.basename must be a string');
|
|
19
|
+
}
|
|
20
|
+
context.appConfig = appConfig;
|
|
21
|
+
}
|
|
22
|
+
next();
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.setupAppConfigMiddleware = setupAppConfigMiddleware;
|
package/lib/server/plugin.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IPluginInstance, IPluginHandlers, HookMap } from '@shuvi/hook';
|
|
2
2
|
import { IPluginContext } from '../core';
|
|
3
3
|
import { CustomServerPluginHooks } from './pluginTypes';
|
|
4
|
+
import { ShuviRequest } from './shuviServerTypes';
|
|
4
5
|
export * from './pluginTypes';
|
|
5
6
|
export interface IServerPluginContext extends IPluginContext {
|
|
6
7
|
serverPluginRunner: PluginManager['runner'];
|
|
8
|
+
appConfig: AppConfig;
|
|
7
9
|
}
|
|
8
10
|
export declare type PluginManager = ReturnType<typeof getManager>;
|
|
9
11
|
export declare type PluginRunner = PluginManager['runner'];
|
|
@@ -11,8 +13,18 @@ declare const listen: import("@shuvi/hook").AsyncParallelHook<{
|
|
|
11
13
|
port: number;
|
|
12
14
|
hostname?: string | undefined;
|
|
13
15
|
}, void, void>;
|
|
16
|
+
declare type AppConfigCtx = {
|
|
17
|
+
req: ShuviRequest;
|
|
18
|
+
};
|
|
19
|
+
declare type AppConfig = {
|
|
20
|
+
router: {
|
|
21
|
+
basename: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
declare const getAppConfig: import("@shuvi/hook").SyncBailHook<void, AppConfigCtx, AppConfig>;
|
|
14
25
|
export interface BuiltInServerPluginHooks extends HookMap {
|
|
15
26
|
listen: typeof listen;
|
|
27
|
+
getAppConfig: typeof getAppConfig;
|
|
16
28
|
}
|
|
17
29
|
export interface ServerPluginHooks extends BuiltInServerPluginHooks, CustomServerPluginHooks {
|
|
18
30
|
}
|
package/lib/server/plugin.js
CHANGED
|
@@ -20,15 +20,23 @@ const hook_1 = require("@shuvi/hook");
|
|
|
20
20
|
const plugins_1 = require("@shuvi/shared/plugins");
|
|
21
21
|
__exportStar(require("./pluginTypes"), exports);
|
|
22
22
|
const listen = (0, hook_1.createAsyncParallelHook)();
|
|
23
|
+
const getAppConfig = (0, hook_1.createSyncBailHook)();
|
|
23
24
|
const internalHooks = {
|
|
24
|
-
listen
|
|
25
|
+
listen,
|
|
26
|
+
getAppConfig
|
|
25
27
|
};
|
|
26
28
|
const getManager = () => (0, hook_1.createHookManager)(internalHooks);
|
|
27
29
|
exports.getManager = getManager;
|
|
28
30
|
_a = (0, plugins_1.createPluginCreator)(), exports.createServerPluginBefore = _a.createPluginBefore, exports.createServerPlugin = _a.createPlugin, exports.createServerPluginAfter = _a.createPluginAfter;
|
|
29
31
|
const initServerPlugins = (manager, serverPlugins, pluginContext) => {
|
|
30
32
|
const serverContext = Object.assign({
|
|
31
|
-
serverPluginRunner: manager.runner
|
|
33
|
+
serverPluginRunner: manager.runner,
|
|
34
|
+
// default appConfig, can be override by setupAppConfigMiddleware
|
|
35
|
+
appConfig: {
|
|
36
|
+
router: {
|
|
37
|
+
basename: ''
|
|
38
|
+
}
|
|
39
|
+
}
|
|
32
40
|
}, pluginContext);
|
|
33
41
|
manager.setContext(serverContext);
|
|
34
42
|
serverPlugins.forEach(plugin => {
|
|
@@ -32,6 +32,7 @@ const devMiddleware_1 = require("./middlewares/dev/devMiddleware");
|
|
|
32
32
|
const httpProxyMiddleware_1 = require("./middlewares/httpProxyMiddleware");
|
|
33
33
|
const getAssetMiddleware_1 = require("./middlewares/getAssetMiddleware");
|
|
34
34
|
const env_1 = require("../config/env");
|
|
35
|
+
const setupAppConfigMiddleware_1 = require("./middlewares/setupAppConfigMiddleware");
|
|
35
36
|
class ShuviDevServer extends shuviServer_1.ShuviServer {
|
|
36
37
|
constructor(corePluginContext, _a) {
|
|
37
38
|
var { bundler } = _a, options = __rest(_a, ["bundler"]);
|
|
@@ -66,6 +67,7 @@ class ShuviDevServer extends shuviServer_1.ShuviServer {
|
|
|
66
67
|
}
|
|
67
68
|
next();
|
|
68
69
|
})));
|
|
70
|
+
server.use((0, setupAppConfigMiddleware_1.setupAppConfigMiddleware)(context));
|
|
69
71
|
if (this._options.getMiddlewaresBeforeDevMiddlewares) {
|
|
70
72
|
const serverMiddlewaresBeforeDevMiddleware = [
|
|
71
73
|
this._options.getMiddlewaresBeforeDevMiddlewares(devMiddleware, context)
|
|
@@ -12,11 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ShuviProdServer = void 0;
|
|
13
13
|
const shuviServer_1 = require("./shuviServer");
|
|
14
14
|
const getAssetMiddleware_1 = require("./middlewares/getAssetMiddleware");
|
|
15
|
+
const setupAppConfigMiddleware_1 = require("./middlewares/setupAppConfigMiddleware");
|
|
15
16
|
class ShuviProdServer extends shuviServer_1.ShuviServer {
|
|
16
17
|
init() {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
const { _serverContext: context } = this;
|
|
19
20
|
this._server.use((0, getAssetMiddleware_1.getAssetMiddleware)(context));
|
|
21
|
+
this._server.use((0, setupAppConfigMiddleware_1.setupAppConfigMiddleware)(context));
|
|
20
22
|
yield this._initMiddlewares();
|
|
21
23
|
});
|
|
22
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"@babel/generator": "7.14.5",
|
|
30
30
|
"@babel/parser": "7.14.7",
|
|
31
31
|
"@babel/traverse": "7.14.7",
|
|
32
|
-
"@shuvi/hook": "1.0.
|
|
33
|
-
"@shuvi/router": "1.0.
|
|
34
|
-
"@shuvi/runtime": "1.0.
|
|
35
|
-
"@shuvi/shared": "1.0.
|
|
36
|
-
"@shuvi/toolpack": "1.0.
|
|
37
|
-
"@shuvi/utils": "1.0.
|
|
38
|
-
"@shuvi/error-overlay": "1.0.
|
|
39
|
-
"@shuvi/reporters": "1.0.
|
|
32
|
+
"@shuvi/hook": "1.0.45",
|
|
33
|
+
"@shuvi/router": "1.0.45",
|
|
34
|
+
"@shuvi/runtime": "1.0.45",
|
|
35
|
+
"@shuvi/shared": "1.0.45",
|
|
36
|
+
"@shuvi/toolpack": "1.0.45",
|
|
37
|
+
"@shuvi/utils": "1.0.45",
|
|
38
|
+
"@shuvi/error-overlay": "1.0.45",
|
|
39
|
+
"@shuvi/reporters": "1.0.45",
|
|
40
40
|
"commander": "5.1.0",
|
|
41
41
|
"comment-json": "4.2.2",
|
|
42
42
|
"cross-spawn": "7.0.3",
|