@modern-js/prod-server 1.1.3 → 1.1.6

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/js/modern/libs/context/context.js +11 -5
  3. package/dist/js/modern/libs/hook-api/route.js +8 -3
  4. package/dist/js/modern/libs/hook-api/template.js +4 -1
  5. package/dist/js/modern/libs/proxy.js +2 -2
  6. package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -2
  7. package/dist/js/modern/libs/render/cache/spr.js +7 -4
  8. package/dist/js/modern/libs/render/reader.js +4 -1
  9. package/dist/js/modern/libs/route/index.js +6 -2
  10. package/dist/js/modern/libs/route/matcher.js +10 -4
  11. package/dist/js/modern/libs/route/route.js +20 -9
  12. package/dist/js/modern/server/index.js +12 -6
  13. package/dist/js/modern/server/modern-server.js +81 -33
  14. package/dist/js/node/libs/context/context.js +11 -5
  15. package/dist/js/node/libs/hook-api/route.js +8 -3
  16. package/dist/js/node/libs/hook-api/template.js +5 -1
  17. package/dist/js/node/libs/proxy.js +2 -2
  18. package/dist/js/node/libs/render/cache/page-caches/lru.js +6 -2
  19. package/dist/js/node/libs/render/cache/spr.js +6 -6
  20. package/dist/js/node/libs/render/reader.js +4 -1
  21. package/dist/js/node/libs/route/index.js +6 -2
  22. package/dist/js/node/libs/route/matcher.js +10 -4
  23. package/dist/js/node/libs/route/route.js +20 -9
  24. package/dist/js/node/server/index.js +12 -6
  25. package/dist/js/node/server/modern-server.js +84 -33
  26. package/dist/types/server/modern-server.d.ts +10 -3
  27. package/package.json +31 -9
  28. package/.eslintrc.js +0 -8
  29. package/dist/js/styles/tsconfig.json +0 -12
  30. package/jest.config.js +0 -8
  31. package/modern.config.js +0 -2
  32. package/src/constants.ts +0 -31
  33. package/src/index.ts +0 -19
  34. package/src/libs/context/context.ts +0 -178
  35. package/src/libs/context/index.ts +0 -7
  36. package/src/libs/hook-api/route.ts +0 -42
  37. package/src/libs/hook-api/template.ts +0 -53
  38. package/src/libs/loadConfig.ts +0 -59
  39. package/src/libs/metrics.ts +0 -15
  40. package/src/libs/proxy.ts +0 -44
  41. package/src/libs/render/cache/__tests__/cache.fun.test.ts +0 -94
  42. package/src/libs/render/cache/__tests__/cache.test.ts +0 -240
  43. package/src/libs/render/cache/__tests__/cacheable.ts +0 -44
  44. package/src/libs/render/cache/__tests__/error-configuration.ts +0 -34
  45. package/src/libs/render/cache/__tests__/matched-cache.ts +0 -88
  46. package/src/libs/render/cache/index.ts +0 -73
  47. package/src/libs/render/cache/page-caches/index.ts +0 -11
  48. package/src/libs/render/cache/page-caches/lru.ts +0 -38
  49. package/src/libs/render/cache/spr.ts +0 -300
  50. package/src/libs/render/cache/type.ts +0 -59
  51. package/src/libs/render/cache/util.ts +0 -94
  52. package/src/libs/render/index.ts +0 -79
  53. package/src/libs/render/measure.ts +0 -66
  54. package/src/libs/render/modern/browser-list.ts +0 -7
  55. package/src/libs/render/modern/index.ts +0 -41
  56. package/src/libs/render/modern/module.d.ts +0 -4
  57. package/src/libs/render/reader.ts +0 -119
  58. package/src/libs/render/ssr.ts +0 -69
  59. package/src/libs/render/static.ts +0 -52
  60. package/src/libs/render/type.ts +0 -38
  61. package/src/libs/route/index.ts +0 -76
  62. package/src/libs/route/matcher.ts +0 -108
  63. package/src/libs/route/route.ts +0 -34
  64. package/src/libs/serve-file.ts +0 -34
  65. package/src/server/index.ts +0 -232
  66. package/src/server/modern-server-split.ts +0 -93
  67. package/src/server/modern-server.ts +0 -620
  68. package/src/tsconfig.json +0 -12
  69. package/src/type.ts +0 -95
  70. package/src/utils.ts +0 -116
  71. package/tsconfig.json +0 -11
package/src/type.ts DELETED
@@ -1,95 +0,0 @@
1
- import { Buffer } from 'buffer';
2
- import { IncomingMessage, Server, ServerResponse } from 'http';
3
- import { serverManager } from '@modern-js/server-core';
4
- import type { ServerPlugin } from '@modern-js/server-core';
5
- import type { NormalizedConfig } from '@modern-js/core';
6
- import type { Metrics, Logger, NextFunction } from '@modern-js/types/server';
7
- import { ModernRouteInterface } from './libs/route';
8
-
9
- declare module 'http' {
10
- interface IncomingMessage {
11
- logger: Logger;
12
- metrics: Metrics;
13
- }
14
- }
15
-
16
- type Plugin = string | [string, any] | ServerPlugin;
17
- export type ModernServerOptions = {
18
- pwd: string;
19
- config: NormalizedConfig;
20
- plugins?: Plugin[];
21
- routes?: ModernRouteInterface[];
22
- staticGenerate?: boolean;
23
- loggerOptions?: Record<string, string>;
24
- metricsOptions?: Record<string, string>;
25
- logger?: Logger;
26
- metrics?: Metrics;
27
- apiOnly?: boolean;
28
- ssrOnly?: boolean;
29
- webOnly?: boolean;
30
- proxyTarget?: {
31
- ssr?: string;
32
- api?: string;
33
- };
34
- runMode?: string;
35
- [propName: string]: any;
36
- };
37
-
38
- export type RenderResult = {
39
- content: string | Buffer;
40
- contentType: string;
41
- statusCode?: number;
42
- redirect?: boolean;
43
- };
44
-
45
- export type ConfWithBFF = {
46
- bff?: {
47
- prefix: string;
48
- };
49
- } & NormalizedConfig;
50
-
51
- export type Then<T> = T extends PromiseLike<infer U> ? U : T;
52
-
53
- export type ServerHookRunner = Then<ReturnType<typeof serverManager.init>>;
54
-
55
- export type BuildOptions = { routes?: ModernRouteInterface[] };
56
-
57
- export type { Metrics, Logger, NextFunction };
58
-
59
- export type HookNames =
60
- | 'beforeMatch'
61
- | 'afterMatch'
62
- | 'beforeRender'
63
- | 'afterRender';
64
-
65
- export interface ModernServerInterface {
66
- pwd: string;
67
-
68
- distDir: string;
69
-
70
- onInit: (runner: ServerHookRunner) => Promise<void>;
71
-
72
- onClose: () => Promise<void>;
73
-
74
- onRepack: (options: BuildOptions) => void;
75
-
76
- onListening: (app: Server) => void;
77
-
78
- getRequestHandler: () => (
79
- req: IncomingMessage,
80
- res: ServerResponse,
81
- next?: () => void,
82
- ) => void;
83
-
84
- createHTTPServer: (
85
- handler: (
86
- req: IncomingMessage,
87
- res: ServerResponse,
88
- next?: () => void,
89
- ) => void,
90
- ) => Promise<Server>;
91
- }
92
-
93
- export type ServerConstructor = (
94
- options: ModernServerOptions,
95
- ) => ModernServerInterface;
package/src/utils.ts DELETED
@@ -1,116 +0,0 @@
1
- import type { NormalizedConfig } from '@modern-js/core';
2
- import { compile } from 'path-to-regexp';
3
- import { createDebugger } from '@modern-js/utils';
4
-
5
- export const debug = createDebugger('prod-server') as any;
6
-
7
- export const mergeExtension = (users: any[]) => {
8
- const output: any[] = [];
9
- return { middleware: output.concat(users) };
10
- };
11
-
12
- export const noop = () => {
13
- // noop
14
- };
15
-
16
- export const createErrorDocument = (status: number, text: string) => {
17
- const title = `${status}: ${text}`;
18
- return `<!DOCTYPE html>
19
- <html lang="en">
20
- <head>
21
- <meta charset="utf-8">
22
- <meta name="viewport" content="width=device-width">
23
- <title>${title}</title>
24
- <style>
25
- html,body {
26
- margin: 0;
27
- }
28
-
29
- .page-container {
30
- color: #000;
31
- background: #fff;
32
- height: 100vh;
33
- text-align: center;
34
- display: flex;
35
- flex-direction: column;
36
- align-items: center;
37
- justify-content: center;
38
- }
39
- </style>
40
- </head>
41
- <body>
42
- <div class="page-container">
43
- <h1>${status}</h1>
44
- <div>${text}</div>
45
- </body>
46
- </html>
47
- `;
48
- };
49
-
50
- export type CollectMiddlewaresResult = {
51
- web: any[];
52
- api: any[];
53
- };
54
-
55
- export const createMiddlewareCollecter = () => {
56
- const webMiddlewares: any[] = [];
57
- const apiMiddlewares: any[] = [];
58
-
59
- const addWebMiddleware = (input: any) => {
60
- webMiddlewares.push(input);
61
- };
62
-
63
- const addAPIMiddleware = (input: any) => {
64
- apiMiddlewares.push(input);
65
- };
66
-
67
- const getMiddlewares = (): CollectMiddlewaresResult => ({
68
- web: webMiddlewares,
69
- api: apiMiddlewares,
70
- });
71
- return {
72
- getMiddlewares,
73
- addWebMiddleware,
74
- addAPIMiddleware,
75
- };
76
- };
77
-
78
- export const toPath = (reg: string, params: Record<string, any>) => {
79
- const fn = compile(reg, { encode: encodeURIComponent });
80
- return fn(params);
81
- };
82
-
83
- export const getStaticReg = (output: NormalizedConfig['output'] = {}) => {
84
- const { favicon, faviconByEntries, cssPath, jsPath, mediaPath } = output;
85
- const favicons = prepareFavicons(favicon, faviconByEntries);
86
- const staticFiles = [cssPath, jsPath, mediaPath].filter(v => Boolean(v));
87
-
88
- const staticPathRegExp = new RegExp(
89
- `^/(static/|upload/|favicon.ico|icon.png${
90
- favicons.length > 0 ? `|${favicons.join('|')}` : ''
91
- }${staticFiles.length > 0 ? `|${staticFiles.join('|')}` : ''})`,
92
- );
93
-
94
- return staticPathRegExp;
95
- };
96
-
97
- export const prepareFavicons = (
98
- favicon: string | undefined,
99
- faviconByEntries?: Record<string, string | undefined>,
100
- ) => {
101
- const faviconNames = [];
102
- if (favicon) {
103
- faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
104
- }
105
- if (faviconByEntries) {
106
- Object.keys(faviconByEntries).forEach(f => {
107
- const curFavicon = faviconByEntries[f];
108
- if (curFavicon) {
109
- faviconNames.push(
110
- curFavicon.substring(curFavicon.lastIndexOf('/') + 1),
111
- );
112
- }
113
- });
114
- }
115
- return faviconNames;
116
- };
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "esModuleInterop": true,
8
- "paths": {}
9
- },
10
- "include": ["src"]
11
- }