@modern-js/server 1.2.1-beta.0 → 1.2.1-beta.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/js/modern/libs/hook-api/template.js +4 -4
- package/dist/js/modern/server/index.js +2 -2
- package/dist/js/modern/server/modern-server.js +2 -1
- package/dist/js/node/libs/hook-api/template.js +4 -4
- package/dist/js/node/server/index.js +2 -2
- package/dist/js/node/server/modern-server.js +2 -1
- package/dist/types/libs/hook-api/template.d.ts +4 -4
- package/dist/types/server/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/libs/hook-api/template.ts +4 -4
- package/src/server/index.ts +2 -2
- package/src/server/modern-server.ts +2 -1
- package/tests/hook.test.ts +4 -4
|
@@ -23,28 +23,28 @@ class TemplateAPI {
|
|
|
23
23
|
this.content = content;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
prependHead(fragment) {
|
|
27
27
|
const {
|
|
28
28
|
head
|
|
29
29
|
} = RegList.before;
|
|
30
30
|
return this.replace(head, `${head}${fragment}`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
appendHead(fragment) {
|
|
34
34
|
const {
|
|
35
35
|
head
|
|
36
36
|
} = RegList.after;
|
|
37
37
|
return this.replace(head, `${fragment}${head}`);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
prependBody(fragment) {
|
|
41
41
|
const {
|
|
42
42
|
body
|
|
43
43
|
} = RegList.before;
|
|
44
44
|
return this.replace(body, `${body}${fragment}`);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
appendBody(fragment) {
|
|
48
48
|
const {
|
|
49
49
|
body
|
|
50
50
|
} = RegList.after;
|
|
@@ -177,6 +177,7 @@ export class ModernServer {
|
|
|
177
177
|
|
|
178
178
|
return [];
|
|
179
179
|
} // add promisify request handler to server
|
|
180
|
+
// handler should do not do more things after invoke next
|
|
180
181
|
|
|
181
182
|
|
|
182
183
|
addHandler(handler) {
|
|
@@ -479,7 +480,7 @@ export class ModernServer {
|
|
|
479
480
|
const injection = JSON.stringify(_objectSpread(_objectSpread({}, manifest), {}, {
|
|
480
481
|
modules
|
|
481
482
|
}));
|
|
482
|
-
templateAPI.
|
|
483
|
+
templateAPI.appendHead(`<script>window.modern_manifest=${injection}</script>`);
|
|
483
484
|
} catch (e) {
|
|
484
485
|
context.error(ERROR_DIGEST.EMICROINJ, e);
|
|
485
486
|
}
|
|
@@ -29,28 +29,28 @@ class TemplateAPI {
|
|
|
29
29
|
this.content = content;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
prependHead(fragment) {
|
|
33
33
|
const {
|
|
34
34
|
head
|
|
35
35
|
} = RegList.before;
|
|
36
36
|
return this.replace(head, `${head}${fragment}`);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
appendHead(fragment) {
|
|
40
40
|
const {
|
|
41
41
|
head
|
|
42
42
|
} = RegList.after;
|
|
43
43
|
return this.replace(head, `${fragment}${head}`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
prependBody(fragment) {
|
|
47
47
|
const {
|
|
48
48
|
body
|
|
49
49
|
} = RegList.before;
|
|
50
50
|
return this.replace(body, `${body}${fragment}`);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
appendBody(fragment) {
|
|
54
54
|
const {
|
|
55
55
|
body
|
|
56
56
|
} = RegList.after;
|
|
@@ -208,6 +208,7 @@ class ModernServer {
|
|
|
208
208
|
|
|
209
209
|
return [];
|
|
210
210
|
} // add promisify request handler to server
|
|
211
|
+
// handler should do not do more things after invoke next
|
|
211
212
|
|
|
212
213
|
|
|
213
214
|
addHandler(handler) {
|
|
@@ -514,7 +515,7 @@ class ModernServer {
|
|
|
514
515
|
const injection = JSON.stringify(_objectSpread(_objectSpread({}, manifest), {}, {
|
|
515
516
|
modules
|
|
516
517
|
}));
|
|
517
|
-
templateAPI.
|
|
518
|
+
templateAPI.appendHead(`<script>window.modern_manifest=${injection}</script>`);
|
|
518
519
|
} catch (e) {
|
|
519
520
|
context.error(_constants.ERROR_DIGEST.EMICROINJ, e);
|
|
520
521
|
}
|
|
@@ -3,10 +3,10 @@ declare class TemplateAPI {
|
|
|
3
3
|
constructor(content: string);
|
|
4
4
|
get(): string;
|
|
5
5
|
set(content: string): void;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
prependHead(fragment: string): this;
|
|
7
|
+
appendHead(fragment: string): this;
|
|
8
|
+
prependBody(fragment: string): this;
|
|
9
|
+
appendBody(fragment: string): this;
|
|
10
10
|
replace(reg: RegExp | string, text: string): this;
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -10,7 +10,7 @@ export declare class Server {
|
|
|
10
10
|
getRequestHandler(): (req: IncomingMessage, res: ServerResponse, next?: (() => void) | undefined) => void;
|
|
11
11
|
ready(readyOptions?: ReadyOptions): void;
|
|
12
12
|
init(): Promise<this>;
|
|
13
|
-
listen(port: number
|
|
13
|
+
listen(port: number, listener: any): void;
|
|
14
14
|
listener(app: httpServer): void;
|
|
15
15
|
close(): Promise<void>;
|
|
16
16
|
private createProdServer;
|
package/package.json
CHANGED
|
@@ -24,22 +24,22 @@ class TemplateAPI {
|
|
|
24
24
|
this.content = content;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public
|
|
27
|
+
public prependHead(fragment: string) {
|
|
28
28
|
const { head } = RegList.before;
|
|
29
29
|
return this.replace(head, `${head}${fragment}`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
public
|
|
32
|
+
public appendHead(fragment: string) {
|
|
33
33
|
const { head } = RegList.after;
|
|
34
34
|
return this.replace(head, `${fragment}${head}`);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
public
|
|
37
|
+
public prependBody(fragment: string) {
|
|
38
38
|
const { body } = RegList.before;
|
|
39
39
|
return this.replace(body, `${body}${fragment}`);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
public
|
|
42
|
+
public appendBody(fragment: string) {
|
|
43
43
|
const { body } = RegList.after;
|
|
44
44
|
return this.replace(body, `${fragment}${body}`);
|
|
45
45
|
}
|
package/src/server/index.ts
CHANGED
|
@@ -67,8 +67,8 @@ export class Server {
|
|
|
67
67
|
return this;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public listen(port
|
|
71
|
-
this.app.listen(port, () => {
|
|
70
|
+
public listen(port: number, listener: any) {
|
|
71
|
+
this.app.listen(port || process.env.PORT, () => {
|
|
72
72
|
if (listener) {
|
|
73
73
|
listener();
|
|
74
74
|
}
|
|
@@ -229,6 +229,7 @@ export class ModernServer {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
// add promisify request handler to server
|
|
232
|
+
// handler should do not do more things after invoke next
|
|
232
233
|
protected addHandler(handler: ModernServerHandler) {
|
|
233
234
|
if ((handler as any)[Symbol.toStringTag] === 'AsyncFunction') {
|
|
234
235
|
this.handlers.push(handler as ModernServerAsyncHandler);
|
|
@@ -502,7 +503,7 @@ export class ModernServer {
|
|
|
502
503
|
try {
|
|
503
504
|
// Todo Safety xss
|
|
504
505
|
const injection = JSON.stringify({ ...manifest, modules });
|
|
505
|
-
templateAPI.
|
|
506
|
+
templateAPI.appendHead(
|
|
506
507
|
`<script>window.modern_manifest=${injection}</script>`,
|
|
507
508
|
);
|
|
508
509
|
} catch (e) {
|
package/tests/hook.test.ts
CHANGED
|
@@ -27,10 +27,10 @@ describe('test hook api', () => {
|
|
|
27
27
|
templateAPI.replace('mock', 'replace');
|
|
28
28
|
expect(templateAPI.get()).toMatch('replace');
|
|
29
29
|
|
|
30
|
-
templateAPI.
|
|
31
|
-
templateAPI.
|
|
32
|
-
templateAPI.
|
|
33
|
-
templateAPI.
|
|
30
|
+
templateAPI.appendBody('after body');
|
|
31
|
+
templateAPI.prependBody('before body');
|
|
32
|
+
templateAPI.appendHead('after head');
|
|
33
|
+
templateAPI.prependHead('before head');
|
|
34
34
|
|
|
35
35
|
const newContent = templateAPI.get();
|
|
36
36
|
expect(newContent).toMatch('<head>before head');
|