@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.
@@ -23,28 +23,28 @@ class TemplateAPI {
23
23
  this.content = content;
24
24
  }
25
25
 
26
- beforeHead(fragment) {
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
- afterHead(fragment) {
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
- beforeBody(fragment) {
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
- afterBody(fragment) {
47
+ appendBody(fragment) {
48
48
  const {
49
49
  body
50
50
  } = RegList.after;
@@ -52,8 +52,8 @@ export class Server {
52
52
  return this;
53
53
  }
54
54
 
55
- listen(port = 8080, listener) {
56
- this.app.listen(port, () => {
55
+ listen(port, listener) {
56
+ this.app.listen(port || process.env.PORT, () => {
57
57
  if (listener) {
58
58
  listener();
59
59
  }
@@ -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.afterHead(`<script>window.modern_manifest=${injection}</script>`);
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
- beforeHead(fragment) {
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
- afterHead(fragment) {
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
- beforeBody(fragment) {
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
- afterBody(fragment) {
53
+ appendBody(fragment) {
54
54
  const {
55
55
  body
56
56
  } = RegList.after;
@@ -68,8 +68,8 @@ class Server {
68
68
  return this;
69
69
  }
70
70
 
71
- listen(port = 8080, listener) {
72
- this.app.listen(port, () => {
71
+ listen(port, listener) {
72
+ this.app.listen(port || process.env.PORT, () => {
73
73
  if (listener) {
74
74
  listener();
75
75
  }
@@ -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.afterHead(`<script>window.modern_manifest=${injection}</script>`);
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
- beforeHead(fragment: string): this;
7
- afterHead(fragment: string): this;
8
- beforeBody(fragment: string): this;
9
- afterBody(fragment: string): this;
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 | undefined, listener: any): void;
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
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.1-beta.0",
14
+ "version": "1.2.1-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -24,22 +24,22 @@ class TemplateAPI {
24
24
  this.content = content;
25
25
  }
26
26
 
27
- public beforeHead(fragment: string) {
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 afterHead(fragment: string) {
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 beforeBody(fragment: string) {
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 afterBody(fragment: string) {
42
+ public appendBody(fragment: string) {
43
43
  const { body } = RegList.after;
44
44
  return this.replace(body, `${fragment}${body}`);
45
45
  }
@@ -67,8 +67,8 @@ export class Server {
67
67
  return this;
68
68
  }
69
69
 
70
- public listen(port = 8080, listener: any) {
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.afterHead(
506
+ templateAPI.appendHead(
506
507
  `<script>window.modern_manifest=${injection}</script>`,
507
508
  );
508
509
  } catch (e) {
@@ -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.afterBody('after body');
31
- templateAPI.beforeBody('before body');
32
- templateAPI.afterHead('after head');
33
- templateAPI.beforeHead('before head');
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');