@modern-js/server-core 2.69.4 → 3.0.0-alpha.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/dist/cjs/adapters/node/helper/index.js +52 -39
- package/dist/cjs/adapters/node/helper/loadCache.js +52 -47
- package/dist/cjs/adapters/node/helper/loadConfig.js +69 -85
- package/dist/cjs/adapters/node/helper/loadEnv.js +60 -50
- package/dist/cjs/adapters/node/helper/loadPlugin.js +40 -32
- package/dist/cjs/adapters/node/helper/utils.js +33 -28
- package/dist/cjs/adapters/node/hono.js +87 -99
- package/dist/cjs/adapters/node/index.js +84 -60
- package/dist/cjs/adapters/node/node.js +164 -190
- package/dist/cjs/adapters/node/plugins/index.js +69 -23
- package/dist/cjs/adapters/node/plugins/nodeServer.js +39 -34
- package/dist/cjs/adapters/node/plugins/resource.js +186 -181
- package/dist/cjs/adapters/node/plugins/static.js +152 -164
- package/dist/cjs/constants.js +70 -57
- package/dist/cjs/context.js +37 -28
- package/dist/cjs/helper.js +40 -33
- package/dist/cjs/hono.js +46 -0
- package/dist/cjs/index.js +236 -57
- package/dist/cjs/plugins/compat/hooks.js +71 -83
- package/dist/cjs/plugins/compat/index.js +59 -60
- package/dist/cjs/plugins/default.js +52 -47
- package/dist/cjs/plugins/favicon.js +43 -39
- package/dist/cjs/plugins/index.js +73 -54
- package/dist/cjs/plugins/log.js +82 -87
- package/dist/cjs/plugins/middlewares.js +43 -37
- package/dist/cjs/plugins/monitors.js +178 -187
- package/dist/cjs/plugins/processedBy.js +45 -39
- package/dist/cjs/plugins/render/csrRscRender.js +70 -71
- package/dist/cjs/plugins/render/dataHandler.js +49 -45
- package/dist/cjs/plugins/render/index.js +152 -126
- package/dist/cjs/plugins/render/inject.js +84 -86
- package/dist/cjs/plugins/render/render.js +244 -271
- package/dist/cjs/plugins/render/renderRscHandler.js +68 -69
- package/dist/cjs/plugins/render/serverActionHandler.js +45 -44
- package/dist/cjs/plugins/render/ssrCache.js +173 -191
- package/dist/cjs/plugins/render/ssrRender.js +89 -94
- package/dist/cjs/plugins/render/utils.js +44 -36
- package/dist/cjs/plugins/route.js +60 -57
- package/dist/cjs/serverBase.js +164 -162
- package/dist/cjs/types/config/bff.js +17 -15
- package/dist/cjs/types/config/dev.js +17 -15
- package/dist/cjs/types/config/html.js +17 -15
- package/dist/cjs/types/config/index.js +90 -29
- package/dist/cjs/types/config/output.js +17 -15
- package/dist/cjs/types/config/security.js +17 -15
- package/dist/cjs/types/config/server.js +17 -15
- package/dist/cjs/types/config/share.js +17 -15
- package/dist/cjs/types/config/source.js +17 -15
- package/dist/cjs/types/config/tools.js +17 -15
- package/dist/cjs/types/index.js +76 -25
- package/dist/cjs/types/plugins/base.js +17 -15
- package/dist/cjs/types/plugins/index.js +55 -21
- package/dist/cjs/types/plugins/plugin.js +18 -0
- package/dist/cjs/types/render.js +17 -15
- package/dist/cjs/types/requestHandler.js +17 -15
- package/dist/cjs/types/server.js +17 -15
- package/dist/cjs/utils/entry.js +37 -32
- package/dist/cjs/utils/env.js +46 -40
- package/dist/cjs/utils/error.js +56 -50
- package/dist/cjs/utils/index.js +111 -33
- package/dist/cjs/utils/middlewareCollector.js +58 -49
- package/dist/cjs/utils/publicDir.js +92 -0
- package/dist/cjs/utils/request.js +73 -65
- package/dist/cjs/utils/serverConfig.js +39 -31
- package/dist/cjs/utils/storage.js +58 -68
- package/dist/cjs/utils/transformStream.js +57 -53
- package/dist/cjs/utils/warmup.js +34 -27
- package/dist/esm/adapters/node/helper/index.mjs +6 -0
- package/dist/esm/adapters/node/helper/loadCache.mjs +14 -0
- package/dist/esm/adapters/node/helper/loadConfig.mjs +31 -0
- package/dist/esm/adapters/node/helper/loadEnv.mjs +22 -0
- package/dist/esm/adapters/node/helper/loadPlugin.mjs +13 -0
- package/dist/esm/adapters/node/helper/utils.mjs +2 -0
- package/dist/esm/adapters/node/hono.mjs +53 -0
- package/dist/esm/adapters/node/index.mjs +5 -0
- package/dist/esm/adapters/node/node.mjs +129 -0
- package/dist/esm/adapters/node/plugins/nodeServer.mjs +9 -0
- package/dist/esm/adapters/node/plugins/resource.mjs +138 -0
- package/dist/esm/adapters/node/plugins/static.mjs +118 -0
- package/dist/esm/constants.mjs +28 -0
- package/dist/{esm-node/context.js → esm/context.mjs} +1 -4
- package/dist/esm/helper.mjs +11 -0
- package/dist/esm/hono.mjs +3 -0
- package/dist/esm/index.mjs +13 -0
- package/dist/esm/plugins/compat/hooks.mjs +40 -0
- package/dist/esm/plugins/compat/index.mjs +27 -0
- package/dist/esm/plugins/default.mjs +25 -0
- package/dist/esm/plugins/favicon.mjs +14 -0
- package/dist/{esm-node/plugins/index.js → esm/plugins/index.mjs} +2 -15
- package/dist/esm/plugins/log.mjs +58 -0
- package/dist/esm/plugins/middlewares.mjs +15 -0
- package/dist/esm/plugins/monitors.mjs +149 -0
- package/dist/esm/plugins/processedBy.mjs +16 -0
- package/dist/esm/plugins/render/csrRscRender.mjs +43 -0
- package/dist/esm/plugins/render/dataHandler.mjs +19 -0
- package/dist/esm/plugins/render/index.mjs +84 -0
- package/dist/esm/plugins/render/inject.mjs +55 -0
- package/dist/esm/plugins/render/render.mjs +226 -0
- package/dist/esm/plugins/render/renderRscHandler.mjs +41 -0
- package/dist/esm/plugins/render/serverActionHandler.mjs +18 -0
- package/dist/esm/plugins/render/ssrCache.mjs +158 -0
- package/dist/esm/plugins/render/ssrRender.mjs +62 -0
- package/dist/esm/plugins/render/utils.mjs +15 -0
- package/dist/esm/plugins/route.mjs +34 -0
- package/dist/esm/serverBase.mjs +136 -0
- package/dist/esm/types/plugins/index.mjs +1 -0
- package/dist/esm/utils/entry.mjs +3 -0
- package/dist/esm/utils/env.mjs +14 -0
- package/dist/esm/utils/error.mjs +53 -0
- package/dist/{esm-node/utils/index.js → esm/utils/index.mjs} +1 -0
- package/dist/esm/utils/middlewareCollector.mjs +26 -0
- package/dist/esm/utils/publicDir.mjs +33 -0
- package/dist/esm/utils/request.mjs +40 -0
- package/dist/esm/utils/serverConfig.mjs +9 -0
- package/dist/esm/utils/storage.mjs +30 -0
- package/dist/esm/utils/transformStream.mjs +28 -0
- package/dist/esm/utils/warmup.mjs +6 -0
- package/dist/esm-node/adapters/node/helper/index.mjs +6 -0
- package/dist/esm-node/adapters/node/helper/loadCache.mjs +14 -0
- package/dist/esm-node/adapters/node/helper/loadConfig.mjs +31 -0
- package/dist/esm-node/adapters/node/helper/loadEnv.mjs +22 -0
- package/dist/esm-node/adapters/node/helper/loadPlugin.mjs +13 -0
- package/dist/esm-node/adapters/node/helper/utils.mjs +2 -0
- package/dist/esm-node/adapters/node/hono.mjs +53 -0
- package/dist/esm-node/adapters/node/index.mjs +5 -0
- package/dist/esm-node/adapters/node/node.mjs +129 -0
- package/dist/esm-node/adapters/node/plugins/index.mjs +3 -0
- package/dist/esm-node/adapters/node/plugins/nodeServer.mjs +9 -0
- package/dist/esm-node/adapters/node/plugins/resource.mjs +138 -0
- package/dist/esm-node/adapters/node/plugins/static.mjs +118 -0
- package/dist/esm-node/constants.mjs +28 -0
- package/dist/esm-node/context.mjs +3 -0
- package/dist/esm-node/helper.mjs +11 -0
- package/dist/esm-node/hono.mjs +3 -0
- package/dist/esm-node/index.mjs +13 -0
- package/dist/esm-node/plugins/compat/hooks.mjs +40 -0
- package/dist/esm-node/plugins/compat/index.mjs +27 -0
- package/dist/esm-node/plugins/default.mjs +25 -0
- package/dist/esm-node/plugins/favicon.mjs +14 -0
- package/dist/esm-node/plugins/index.mjs +9 -0
- package/dist/esm-node/plugins/log.mjs +58 -0
- package/dist/esm-node/plugins/middlewares.mjs +15 -0
- package/dist/esm-node/plugins/monitors.mjs +149 -0
- package/dist/esm-node/plugins/processedBy.mjs +16 -0
- package/dist/esm-node/plugins/render/csrRscRender.mjs +43 -0
- package/dist/esm-node/plugins/render/dataHandler.mjs +19 -0
- package/dist/esm-node/plugins/render/index.mjs +84 -0
- package/dist/esm-node/plugins/render/inject.mjs +55 -0
- package/dist/esm-node/plugins/render/render.mjs +226 -0
- package/dist/esm-node/plugins/render/renderRscHandler.mjs +41 -0
- package/dist/esm-node/plugins/render/serverActionHandler.mjs +18 -0
- package/dist/esm-node/plugins/render/ssrCache.mjs +158 -0
- package/dist/esm-node/plugins/render/ssrRender.mjs +62 -0
- package/dist/esm-node/plugins/render/utils.mjs +15 -0
- package/dist/esm-node/plugins/route.mjs +34 -0
- package/dist/esm-node/serverBase.mjs +136 -0
- package/dist/esm-node/types/config/index.mjs +6 -0
- package/dist/esm-node/types/index.mjs +4 -0
- package/dist/esm-node/types/plugins/index.mjs +1 -0
- package/dist/esm-node/utils/entry.mjs +3 -0
- package/dist/esm-node/utils/env.mjs +14 -0
- package/dist/esm-node/utils/error.mjs +53 -0
- package/dist/esm-node/utils/index.mjs +9 -0
- package/dist/esm-node/utils/middlewareCollector.mjs +26 -0
- package/dist/esm-node/utils/publicDir.mjs +33 -0
- package/dist/esm-node/utils/request.mjs +40 -0
- package/dist/esm-node/utils/serverConfig.mjs +9 -0
- package/dist/esm-node/utils/storage.mjs +30 -0
- package/dist/esm-node/utils/transformStream.mjs +28 -0
- package/dist/esm-node/utils/warmup.mjs +6 -0
- package/dist/types/adapters/node/helper/loadConfig.d.ts +1 -1
- package/dist/types/adapters/node/plugins/nodeServer.d.ts +2 -2
- package/dist/types/adapters/node/plugins/resource.d.ts +3 -3
- package/dist/types/adapters/node/plugins/static.d.ts +3 -2
- package/dist/types/hono.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/compat/hooks.d.ts +1 -1
- package/dist/types/plugins/default.d.ts +2 -2
- package/dist/types/plugins/favicon.d.ts +2 -2
- package/dist/types/plugins/log.d.ts +2 -2
- package/dist/types/plugins/middlewares.d.ts +2 -2
- package/dist/types/plugins/monitors.d.ts +4 -4
- package/dist/types/plugins/processedBy.d.ts +2 -2
- package/dist/types/plugins/render/dataHandler.d.ts +1 -1
- package/dist/types/plugins/render/index.d.ts +2 -2
- package/dist/types/plugins/render/inject.d.ts +2 -2
- package/dist/types/plugins/render/ssrRender.d.ts +3 -5
- package/dist/types/plugins/route.d.ts +2 -2
- package/dist/types/serverBase.d.ts +14 -20
- package/dist/types/types/config/bff.d.ts +0 -2
- package/dist/types/types/config/html.d.ts +0 -1
- package/dist/types/types/config/index.d.ts +0 -6
- package/dist/types/types/config/output.d.ts +2 -8
- package/dist/types/types/config/server.d.ts +1 -1
- package/dist/types/types/plugins/base.d.ts +5 -26
- package/dist/types/types/plugins/index.d.ts +1 -2
- package/dist/types/types/plugins/{new.d.ts → plugin.d.ts} +6 -4
- package/dist/types/types/render.d.ts +2 -5
- package/dist/types/types/requestHandler.d.ts +3 -7
- package/dist/types/types/server.d.ts +2 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/publicDir.d.ts +40 -0
- package/dist/types/utils/transformStream.d.ts +1 -1
- package/package.json +25 -29
- package/rslib.config.mts +4 -0
- package/rstest.config.ts +7 -0
- package/dist/cjs/plugins/customServer/base.js +0 -186
- package/dist/cjs/plugins/customServer/context.js +0 -70
- package/dist/cjs/plugins/customServer/index.js +0 -210
- package/dist/cjs/plugins/customServer/routerApi.js +0 -44
- package/dist/cjs/plugins/customServer/template.js +0 -58
- package/dist/cjs/types/plugins/new.js +0 -16
- package/dist/cjs/types/plugins/old.js +0 -16
- package/dist/esm/adapters/node/helper/index.js +0 -13
- package/dist/esm/adapters/node/helper/loadCache.js +0 -44
- package/dist/esm/adapters/node/helper/loadConfig.js +0 -157
- package/dist/esm/adapters/node/helper/loadEnv.js +0 -73
- package/dist/esm/adapters/node/helper/loadPlugin.js +0 -59
- package/dist/esm/adapters/node/helper/utils.js +0 -7
- package/dist/esm/adapters/node/hono.js +0 -148
- package/dist/esm/adapters/node/index.js +0 -23
- package/dist/esm/adapters/node/node.js +0 -357
- package/dist/esm/adapters/node/plugins/index.js +0 -3
- package/dist/esm/adapters/node/plugins/nodeServer.js +0 -18
- package/dist/esm/adapters/node/plugins/resource.js +0 -543
- package/dist/esm/adapters/node/plugins/static.js +0 -245
- package/dist/esm/constants.js +0 -35
- package/dist/esm/context.js +0 -6
- package/dist/esm/helper.js +0 -14
- package/dist/esm/index.js +0 -22
- package/dist/esm/plugins/compat/hooks.js +0 -70
- package/dist/esm/plugins/compat/index.js +0 -45
- package/dist/esm/plugins/customServer/base.js +0 -218
- package/dist/esm/plugins/customServer/context.js +0 -66
- package/dist/esm/plugins/customServer/index.js +0 -369
- package/dist/esm/plugins/customServer/routerApi.js +0 -26
- package/dist/esm/plugins/customServer/template.js +0 -47
- package/dist/esm/plugins/default.js +0 -31
- package/dist/esm/plugins/favicon.js +0 -34
- package/dist/esm/plugins/index.js +0 -22
- package/dist/esm/plugins/log.js +0 -106
- package/dist/esm/plugins/middlewares.js +0 -22
- package/dist/esm/plugins/monitors.js +0 -287
- package/dist/esm/plugins/processedBy.js +0 -42
- package/dist/esm/plugins/render/csrRscRender.js +0 -88
- package/dist/esm/plugins/render/dataHandler.js +0 -48
- package/dist/esm/plugins/render/index.js +0 -215
- package/dist/esm/plugins/render/inject.js +0 -126
- package/dist/esm/plugins/render/render.js +0 -572
- package/dist/esm/plugins/render/renderRscHandler.js +0 -81
- package/dist/esm/plugins/render/serverActionHandler.js +0 -49
- package/dist/esm/plugins/render/ssrCache.js +0 -305
- package/dist/esm/plugins/render/ssrRender.js +0 -124
- package/dist/esm/plugins/render/utils.js +0 -17
- package/dist/esm/plugins/route.js +0 -92
- package/dist/esm/serverBase.js +0 -248
- package/dist/esm/types/config/index.js +0 -6
- package/dist/esm/types/index.js +0 -4
- package/dist/esm/types/plugins/index.js +0 -2
- package/dist/esm/types/requestHandler.js +0 -0
- package/dist/esm/types/server.js +0 -0
- package/dist/esm/utils/entry.js +0 -10
- package/dist/esm/utils/env.js +0 -20
- package/dist/esm/utils/error.js +0 -33
- package/dist/esm/utils/index.js +0 -8
- package/dist/esm/utils/middlewareCollector.js +0 -31
- package/dist/esm/utils/request.js +0 -51
- package/dist/esm/utils/serverConfig.js +0 -13
- package/dist/esm/utils/storage.js +0 -38
- package/dist/esm/utils/transformStream.js +0 -104
- package/dist/esm/utils/warmup.js +0 -9
- package/dist/esm-node/adapters/node/helper/index.js +0 -13
- package/dist/esm-node/adapters/node/helper/loadCache.js +0 -19
- package/dist/esm-node/adapters/node/helper/loadConfig.js +0 -59
- package/dist/esm-node/adapters/node/helper/loadEnv.js +0 -22
- package/dist/esm-node/adapters/node/helper/loadPlugin.js +0 -15
- package/dist/esm-node/adapters/node/helper/utils.js +0 -7
- package/dist/esm-node/adapters/node/hono.js +0 -79
- package/dist/esm-node/adapters/node/index.js +0 -23
- package/dist/esm-node/adapters/node/node.js +0 -169
- package/dist/esm-node/adapters/node/plugins/nodeServer.js +0 -14
- package/dist/esm-node/adapters/node/plugins/resource.js +0 -159
- package/dist/esm-node/adapters/node/plugins/static.js +0 -144
- package/dist/esm-node/constants.js +0 -35
- package/dist/esm-node/helper.js +0 -14
- package/dist/esm-node/index.js +0 -22
- package/dist/esm-node/plugins/compat/hooks.js +0 -66
- package/dist/esm-node/plugins/compat/index.js +0 -40
- package/dist/esm-node/plugins/customServer/base.js +0 -162
- package/dist/esm-node/plugins/customServer/context.js +0 -43
- package/dist/esm-node/plugins/customServer/index.js +0 -185
- package/dist/esm-node/plugins/customServer/routerApi.js +0 -20
- package/dist/esm-node/plugins/customServer/template.js +0 -34
- package/dist/esm-node/plugins/default.js +0 -30
- package/dist/esm-node/plugins/favicon.js +0 -20
- package/dist/esm-node/plugins/log.js +0 -73
- package/dist/esm-node/plugins/middlewares.js +0 -19
- package/dist/esm-node/plugins/monitors.js +0 -174
- package/dist/esm-node/plugins/processedBy.js +0 -20
- package/dist/esm-node/plugins/render/csrRscRender.js +0 -54
- package/dist/esm-node/plugins/render/dataHandler.js +0 -25
- package/dist/esm-node/plugins/render/index.js +0 -106
- package/dist/esm-node/plugins/render/inject.js +0 -69
- package/dist/esm-node/plugins/render/render.js +0 -253
- package/dist/esm-node/plugins/render/renderRscHandler.js +0 -52
- package/dist/esm-node/plugins/render/serverActionHandler.js +0 -27
- package/dist/esm-node/plugins/render/ssrCache.js +0 -190
- package/dist/esm-node/plugins/render/ssrRender.js +0 -77
- package/dist/esm-node/plugins/render/utils.js +0 -17
- package/dist/esm-node/plugins/route.js +0 -41
- package/dist/esm-node/serverBase.js +0 -146
- package/dist/esm-node/types/plugins/index.js +0 -2
- package/dist/esm-node/utils/entry.js +0 -10
- package/dist/esm-node/utils/env.js +0 -20
- package/dist/esm-node/utils/error.js +0 -61
- package/dist/esm-node/utils/middlewareCollector.js +0 -29
- package/dist/esm-node/utils/request.js +0 -50
- package/dist/esm-node/utils/serverConfig.js +0 -11
- package/dist/esm-node/utils/storage.js +0 -40
- package/dist/esm-node/utils/transformStream.js +0 -36
- package/dist/esm-node/utils/warmup.js +0 -9
- package/dist/types/plugins/customServer/base.d.ts +0 -7
- package/dist/types/plugins/customServer/context.d.ts +0 -8
- package/dist/types/plugins/customServer/index.d.ts +0 -11
- package/dist/types/plugins/customServer/routerApi.d.ts +0 -9
- package/dist/types/plugins/customServer/template.d.ts +0 -11
- package/dist/types/types/plugins/old.d.ts +0 -56
- /package/dist/{esm-node/adapters/node/plugins/index.js → esm/adapters/node/plugins/index.mjs} +0 -0
- /package/dist/{esm-node/types/server.js → esm/types/config/bff.mjs} +0 -0
- /package/dist/esm/types/config/{bff.js → dev.mjs} +0 -0
- /package/dist/esm/types/config/{dev.js → html.mjs} +0 -0
- /package/dist/{esm-node/types/config/index.js → esm/types/config/index.mjs} +0 -0
- /package/dist/esm/types/config/{html.js → output.mjs} +0 -0
- /package/dist/esm/types/config/{output.js → security.mjs} +0 -0
- /package/dist/esm/types/config/{security.js → server.mjs} +0 -0
- /package/dist/esm/types/config/{server.js → share.mjs} +0 -0
- /package/dist/esm/types/config/{share.js → source.mjs} +0 -0
- /package/dist/esm/types/config/{source.js → tools.mjs} +0 -0
- /package/dist/{esm-node/types/index.js → esm/types/index.mjs} +0 -0
- /package/dist/esm/types/{config/tools.js → plugins/base.mjs} +0 -0
- /package/dist/esm/types/plugins/{base.js → plugin.mjs} +0 -0
- /package/dist/esm/types/{plugins/new.js → render.mjs} +0 -0
- /package/dist/esm/types/{plugins/old.js → requestHandler.mjs} +0 -0
- /package/dist/esm/types/{render.js → server.mjs} +0 -0
- /package/dist/esm-node/types/config/{bff.js → bff.mjs} +0 -0
- /package/dist/esm-node/types/config/{dev.js → dev.mjs} +0 -0
- /package/dist/esm-node/types/config/{html.js → html.mjs} +0 -0
- /package/dist/esm-node/types/config/{output.js → output.mjs} +0 -0
- /package/dist/esm-node/types/config/{security.js → security.mjs} +0 -0
- /package/dist/esm-node/types/config/{server.js → server.mjs} +0 -0
- /package/dist/esm-node/types/config/{share.js → share.mjs} +0 -0
- /package/dist/esm-node/types/config/{source.js → source.mjs} +0 -0
- /package/dist/esm-node/types/config/{tools.js → tools.mjs} +0 -0
- /package/dist/esm-node/types/plugins/{base.js → base.mjs} +0 -0
- /package/dist/esm-node/types/plugins/{new.js → plugin.mjs} +0 -0
- /package/dist/esm-node/types/{plugins/old.js → render.mjs} +0 -0
- /package/dist/esm-node/types/{render.js → requestHandler.mjs} +0 -0
- /package/dist/esm-node/types/{requestHandler.js → server.mjs} +0 -0
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fs, DEFAULT_SERVER_CONFIG, OUTPUT_CONFIG_FILE, lodash as _, chalk, compatibleRequire, ensureAbsolutePath, getMeta, requireExistModule } from "@modern-js/utils";
|
|
3
|
-
import { parse } from "flatted";
|
|
4
|
-
const requireConfig = async (serverConfigPath) => {
|
|
5
|
-
if (fs.pathExistsSync(serverConfigPath)) {
|
|
6
|
-
return compatibleRequire(serverConfigPath);
|
|
7
|
-
}
|
|
8
|
-
return void 0;
|
|
9
|
-
};
|
|
10
|
-
async function loadServerConfigNew(serverConfigPath) {
|
|
11
|
-
const mod = await requireExistModule(serverConfigPath);
|
|
12
|
-
if (mod) {
|
|
13
|
-
return mod;
|
|
14
|
-
}
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
async function loadServerConfigOld(pwd, configFile) {
|
|
18
|
-
const serverConfigPath = path.join(pwd, `${configFile}.cjs`);
|
|
19
|
-
const serverConfig = await requireConfig(serverConfigPath);
|
|
20
|
-
return serverConfig;
|
|
21
|
-
}
|
|
22
|
-
async function loadServerRuntimeConfig(pwd, oldServerFile = DEFAULT_SERVER_CONFIG, newServerConfigPath, metaName) {
|
|
23
|
-
const newServerConfig = newServerConfigPath && await loadServerConfigNew(newServerConfigPath);
|
|
24
|
-
if (newServerConfig) {
|
|
25
|
-
return newServerConfig;
|
|
26
|
-
}
|
|
27
|
-
const oldServerConfig = await loadServerConfigOld(pwd, oldServerFile);
|
|
28
|
-
if (oldServerConfig) {
|
|
29
|
-
const meta = getMeta(metaName);
|
|
30
|
-
console.warn(`${chalk.red("\n[Warning]")} ${chalk.yellow.bold(`\`${oldServerFile}\``)} is no longer maintained. To extend the server, please migrate to ${chalk.yellow.bold(`\`server/${meta}.server.ts\``)};`);
|
|
31
|
-
}
|
|
32
|
-
return oldServerConfig;
|
|
33
|
-
}
|
|
34
|
-
function loadServerCliConfig(pwd, defaultConfig = {}) {
|
|
35
|
-
var _defaultConfig_output_distPath, _defaultConfig_output;
|
|
36
|
-
const cliConfigPath = ensureAbsolutePath(pwd, path.join(((_defaultConfig_output = defaultConfig.output) === null || _defaultConfig_output === void 0 ? void 0 : (_defaultConfig_output_distPath = _defaultConfig_output.distPath) === null || _defaultConfig_output_distPath === void 0 ? void 0 : _defaultConfig_output_distPath.root) || "dist", OUTPUT_CONFIG_FILE));
|
|
37
|
-
let cliConfig = {
|
|
38
|
-
output: {},
|
|
39
|
-
source: {},
|
|
40
|
-
tools: {},
|
|
41
|
-
server: {},
|
|
42
|
-
security: {},
|
|
43
|
-
runtime: {},
|
|
44
|
-
bff: {},
|
|
45
|
-
html: {},
|
|
46
|
-
dev: {}
|
|
47
|
-
};
|
|
48
|
-
try {
|
|
49
|
-
const content = fs.readFileSync(cliConfigPath, "utf-8");
|
|
50
|
-
cliConfig = parse(content);
|
|
51
|
-
} catch (_2) {
|
|
52
|
-
}
|
|
53
|
-
const mergedCliConfig = _.merge(defaultConfig, cliConfig);
|
|
54
|
-
return mergedCliConfig;
|
|
55
|
-
}
|
|
56
|
-
export {
|
|
57
|
-
loadServerCliConfig,
|
|
58
|
-
loadServerRuntimeConfig
|
|
59
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fs, dotenv, dotenvExpand } from "@modern-js/utils";
|
|
3
|
-
async function loadServerEnv(options) {
|
|
4
|
-
const { pwd } = options;
|
|
5
|
-
const serverEnv = process.env.MODERN_ENV;
|
|
6
|
-
const defaultEnvPath = path.resolve(pwd, `.env`);
|
|
7
|
-
const serverEnvPath = path.resolve(pwd, `.env.${serverEnv}`);
|
|
8
|
-
for (const envPath of [
|
|
9
|
-
serverEnvPath,
|
|
10
|
-
defaultEnvPath
|
|
11
|
-
]) {
|
|
12
|
-
if (await fs.pathExists(envPath) && !(await fs.stat(envPath)).isDirectory()) {
|
|
13
|
-
const envConfig = dotenv.config({
|
|
14
|
-
path: envPath
|
|
15
|
-
});
|
|
16
|
-
dotenvExpand(envConfig);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
loadServerEnv
|
|
22
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { compatibleRequire, tryResolve } from "@modern-js/utils";
|
|
2
|
-
async function resolveServerPlugin(plugin, appDirectory) {
|
|
3
|
-
const { name, options } = plugin;
|
|
4
|
-
const pluginPath = tryResolve(name, appDirectory);
|
|
5
|
-
const module = await compatibleRequire(pluginPath);
|
|
6
|
-
const pluginInstance = module(options);
|
|
7
|
-
return pluginInstance;
|
|
8
|
-
}
|
|
9
|
-
async function loadServerPlugins(serverPlugins, appDirectory) {
|
|
10
|
-
const instances = await Promise.all(serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory)));
|
|
11
|
-
return instances;
|
|
12
|
-
}
|
|
13
|
-
export {
|
|
14
|
-
loadServerPlugins
|
|
15
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const isResFinalized = (res) => {
|
|
2
|
-
var _res_socket;
|
|
3
|
-
return res.headersSent || res._modernBodyPiped || res.writableEnded || res.finished || !((_res_socket = res.socket) === null || _res_socket === void 0 ? void 0 : _res_socket.writable);
|
|
4
|
-
};
|
|
5
|
-
export {
|
|
6
|
-
isResFinalized
|
|
7
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { isResFinalized } from "./helper";
|
|
2
|
-
const httpCallBack2HonoMid = (handler) => {
|
|
3
|
-
return async (context, next) => {
|
|
4
|
-
const { req, res } = context.env.node;
|
|
5
|
-
const onPipe = () => {
|
|
6
|
-
res._modernBodyPiped = true;
|
|
7
|
-
};
|
|
8
|
-
res.once("pipe", onPipe);
|
|
9
|
-
req.__honoRequest = context.req;
|
|
10
|
-
req.__templates = context.get("templates") || {};
|
|
11
|
-
req.__serverManifest = context.get("serverManifest") || {};
|
|
12
|
-
req.__rscServerManifest = context.get("rscServerManifest");
|
|
13
|
-
req.__rscClientManifest = context.get("rscClientManifest");
|
|
14
|
-
req.__rscSSRManifest = context.get("rscSSRManifest");
|
|
15
|
-
try {
|
|
16
|
-
await handler(req, res);
|
|
17
|
-
} finally {
|
|
18
|
-
delete req.__honoRequest;
|
|
19
|
-
delete req.__templates;
|
|
20
|
-
delete req.__serverManifest;
|
|
21
|
-
delete req.__rscServerManifest;
|
|
22
|
-
delete req.__rscClientManifest;
|
|
23
|
-
delete req.__rscSSRManifest;
|
|
24
|
-
res.removeListener("pipe", onPipe);
|
|
25
|
-
}
|
|
26
|
-
if (isResFinalized(res)) {
|
|
27
|
-
context.finalized = true;
|
|
28
|
-
} else {
|
|
29
|
-
await next();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const noop = () => {
|
|
34
|
-
};
|
|
35
|
-
const connectMid2HonoMid = (handler) => {
|
|
36
|
-
return async (context, next) => {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
const { req, res } = context.env.node;
|
|
39
|
-
if (handler.length < 3) {
|
|
40
|
-
resolve(handler(req, res, noop));
|
|
41
|
-
} else {
|
|
42
|
-
handler(req, res, (err) => {
|
|
43
|
-
if (err) {
|
|
44
|
-
reject(err);
|
|
45
|
-
} else {
|
|
46
|
-
resolve(next());
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
const connectMockMid2HonoMid = (handler) => {
|
|
54
|
-
return async (context, next) => {
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
const { req, res } = context.env.node;
|
|
57
|
-
if (handler.length < 3) {
|
|
58
|
-
res.once("finish", () => {
|
|
59
|
-
context.finalized = true;
|
|
60
|
-
resolve();
|
|
61
|
-
});
|
|
62
|
-
handler(req, res, noop);
|
|
63
|
-
} else {
|
|
64
|
-
handler(req, res, (err) => {
|
|
65
|
-
if (err) {
|
|
66
|
-
reject(err);
|
|
67
|
-
} else {
|
|
68
|
-
resolve(next());
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export {
|
|
76
|
-
connectMid2HonoMid,
|
|
77
|
-
connectMockMid2HonoMid,
|
|
78
|
-
httpCallBack2HonoMid
|
|
79
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { httpCallBack2HonoMid, connectMid2HonoMid, connectMockMid2HonoMid } from "./hono";
|
|
2
|
-
import { createNodeServer, sendResponse, createWebRequest } from "./node";
|
|
3
|
-
import { serverStaticPlugin, injectResourcePlugin, getHtmlTemplates, getServerManifest, injectNodeSeverPlugin, injectRscManifestPlugin } from "./plugins";
|
|
4
|
-
import { loadServerPlugins, loadServerEnv, loadServerRuntimeConfig, loadServerCliConfig, loadCacheConfig } from "./helper";
|
|
5
|
-
export {
|
|
6
|
-
connectMid2HonoMid,
|
|
7
|
-
connectMockMid2HonoMid,
|
|
8
|
-
createNodeServer,
|
|
9
|
-
createWebRequest,
|
|
10
|
-
getHtmlTemplates,
|
|
11
|
-
getServerManifest,
|
|
12
|
-
httpCallBack2HonoMid,
|
|
13
|
-
injectNodeSeverPlugin,
|
|
14
|
-
injectResourcePlugin,
|
|
15
|
-
injectRscManifestPlugin,
|
|
16
|
-
loadCacheConfig,
|
|
17
|
-
loadServerCliConfig,
|
|
18
|
-
loadServerEnv,
|
|
19
|
-
loadServerPlugins,
|
|
20
|
-
loadServerRuntimeConfig,
|
|
21
|
-
sendResponse,
|
|
22
|
-
serverStaticPlugin
|
|
23
|
-
};
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { ServerResponse } from "node:http";
|
|
2
|
-
import { Readable, Writable } from "node:stream";
|
|
3
|
-
import cloneable from "cloneable-readable";
|
|
4
|
-
import { isResFinalized } from "./helper";
|
|
5
|
-
const createWebRequest = (req, res, body) => {
|
|
6
|
-
const headerRecord = [];
|
|
7
|
-
for (const [key, value] of Object.entries(req.headers)) {
|
|
8
|
-
if (key.startsWith(":")) {
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(value)) {
|
|
12
|
-
for (const item of value) {
|
|
13
|
-
if (item !== void 0) {
|
|
14
|
-
headerRecord.push([
|
|
15
|
-
key,
|
|
16
|
-
item
|
|
17
|
-
]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
} else if (value !== void 0) {
|
|
21
|
-
if (typeof value === "string") {
|
|
22
|
-
headerRecord.push([
|
|
23
|
-
key,
|
|
24
|
-
value
|
|
25
|
-
]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const { method } = req;
|
|
30
|
-
const controller = new AbortController();
|
|
31
|
-
const init = {
|
|
32
|
-
method,
|
|
33
|
-
headers: headerRecord,
|
|
34
|
-
signal: controller.signal
|
|
35
|
-
};
|
|
36
|
-
res.on("close", () => controller.abort("res closed"));
|
|
37
|
-
const url = `http://${req.headers.host}${req.url}`;
|
|
38
|
-
const needsRequestBody = body || !(method === "GET" || method === "HEAD");
|
|
39
|
-
const cloneableReq = needsRequestBody ? cloneable(req) : null;
|
|
40
|
-
if (needsRequestBody) {
|
|
41
|
-
if (body) {
|
|
42
|
-
init.body = body;
|
|
43
|
-
} else {
|
|
44
|
-
const stream = cloneableReq.clone();
|
|
45
|
-
init.body = Readable.toWeb(stream);
|
|
46
|
-
}
|
|
47
|
-
init.duplex = "half";
|
|
48
|
-
}
|
|
49
|
-
const originalRequest = new Request(url, init);
|
|
50
|
-
if (needsRequestBody) {
|
|
51
|
-
const interceptedMethods = [
|
|
52
|
-
"json",
|
|
53
|
-
"text",
|
|
54
|
-
"blob",
|
|
55
|
-
"arrayBuffer",
|
|
56
|
-
"formData"
|
|
57
|
-
];
|
|
58
|
-
return new Proxy(originalRequest, {
|
|
59
|
-
get(target, prop) {
|
|
60
|
-
if (interceptedMethods.includes(prop)) {
|
|
61
|
-
return (...args) => {
|
|
62
|
-
cloneableReq.resume();
|
|
63
|
-
return target[prop].call(target, ...args);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const value = target[prop];
|
|
67
|
-
if (prop === "body") {
|
|
68
|
-
cloneableReq.resume();
|
|
69
|
-
return value;
|
|
70
|
-
}
|
|
71
|
-
if (typeof value === "function") {
|
|
72
|
-
return (...args) => value.apply(target, args);
|
|
73
|
-
}
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return originalRequest;
|
|
79
|
-
};
|
|
80
|
-
const sendResponse = async (response, res) => {
|
|
81
|
-
var _response_headers_get;
|
|
82
|
-
res.statusMessage = response.statusText;
|
|
83
|
-
res.statusCode = response.status;
|
|
84
|
-
const cookies = [];
|
|
85
|
-
for (const [key, value] of response.headers.entries()) {
|
|
86
|
-
if (key === "set-cookie") {
|
|
87
|
-
cookies.push(value);
|
|
88
|
-
} else {
|
|
89
|
-
res.setHeader(key, value);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (cookies.length > 0) {
|
|
93
|
-
res.setHeader("set-cookie", cookies);
|
|
94
|
-
}
|
|
95
|
-
if (((_response_headers_get = response.headers.get("Content-Type")) === null || _response_headers_get === void 0 ? void 0 : _response_headers_get.match(/text\/event-stream/i)) && res instanceof ServerResponse) {
|
|
96
|
-
res.flushHeaders();
|
|
97
|
-
}
|
|
98
|
-
if (response.body) {
|
|
99
|
-
const writable = Writable.toWeb(res);
|
|
100
|
-
await response.body.pipeTo(writable);
|
|
101
|
-
} else {
|
|
102
|
-
res.end();
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const handleResponseError = (e, res) => {
|
|
106
|
-
const err = e instanceof Error ? e : new Error("unknown error", {
|
|
107
|
-
cause: e
|
|
108
|
-
});
|
|
109
|
-
if (err.code === "ABORT_ERR" || err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
110
|
-
console.info("The user aborted a request.");
|
|
111
|
-
} else {
|
|
112
|
-
console.error(e);
|
|
113
|
-
if (!res.headersSent) {
|
|
114
|
-
res.writeHead(500, {
|
|
115
|
-
"Content-Type": "text/plain"
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
res.end(`Error: ${err.message}`);
|
|
119
|
-
res.destroy(err);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const getRequestListener = (handler) => {
|
|
123
|
-
return async (req, res) => {
|
|
124
|
-
try {
|
|
125
|
-
const request = createWebRequest(req, res);
|
|
126
|
-
const response = await handler(request, {
|
|
127
|
-
node: {
|
|
128
|
-
req,
|
|
129
|
-
res
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
if (!response.res && !isResFinalized(res)) {
|
|
133
|
-
await sendResponse(response, res);
|
|
134
|
-
}
|
|
135
|
-
} catch (error) {
|
|
136
|
-
return handleResponseError(error, res);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
const createNodeServer = async (requestHandler, httpsOptions, http2) => {
|
|
141
|
-
const requestListener = getRequestListener(requestHandler);
|
|
142
|
-
let nodeServer;
|
|
143
|
-
if (httpsOptions) {
|
|
144
|
-
if (http2) {
|
|
145
|
-
const { createSecureServer } = await import("node:http2");
|
|
146
|
-
nodeServer = createSecureServer({
|
|
147
|
-
allowHTTP1: true,
|
|
148
|
-
maxSessionMemory: 1024,
|
|
149
|
-
...httpsOptions
|
|
150
|
-
}, (req, res) => {
|
|
151
|
-
return requestListener(req, res);
|
|
152
|
-
});
|
|
153
|
-
} else {
|
|
154
|
-
const { createServer } = await import("node:https");
|
|
155
|
-
nodeServer = createServer(httpsOptions, requestListener);
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
const { createServer } = await import("node:http");
|
|
159
|
-
nodeServer = createServer(requestListener);
|
|
160
|
-
}
|
|
161
|
-
nodeServer.getRequestListener = () => requestListener;
|
|
162
|
-
nodeServer.getRequestHandler = () => requestHandler;
|
|
163
|
-
return nodeServer;
|
|
164
|
-
};
|
|
165
|
-
export {
|
|
166
|
-
createNodeServer,
|
|
167
|
-
createWebRequest,
|
|
168
|
-
sendResponse
|
|
169
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const injectNodeSeverPlugin = ({ nodeServer }) => ({
|
|
2
|
-
name: "@modern-js/plugin-inject-node-server",
|
|
3
|
-
setup(api) {
|
|
4
|
-
const appContext = api.useAppContext();
|
|
5
|
-
api.setAppContext({
|
|
6
|
-
...appContext,
|
|
7
|
-
nodeServer
|
|
8
|
-
});
|
|
9
|
-
return {};
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
export {
|
|
13
|
-
injectNodeSeverPlugin
|
|
14
|
-
};
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
3
|
-
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire, isProd } from "@modern-js/utils";
|
|
4
|
-
import { uniqueKeyByRoute } from "../../../utils";
|
|
5
|
-
async function getHtmlTemplates(pwd, routes) {
|
|
6
|
-
const htmlRoutes = routes.filter((route) => route.entryName);
|
|
7
|
-
const htmls = await Promise.all(htmlRoutes.map(async (route) => {
|
|
8
|
-
let html;
|
|
9
|
-
try {
|
|
10
|
-
var _this;
|
|
11
|
-
const htmlPath = path.join(pwd, route.entryPath);
|
|
12
|
-
html = (_this = await fileReader.readFile(htmlPath, "utf-8")) === null || _this === void 0 ? void 0 : _this.toString();
|
|
13
|
-
} catch (e) {
|
|
14
|
-
}
|
|
15
|
-
return [
|
|
16
|
-
uniqueKeyByRoute(route),
|
|
17
|
-
html
|
|
18
|
-
];
|
|
19
|
-
}) || []);
|
|
20
|
-
const templates = Object.fromEntries(htmls);
|
|
21
|
-
return templates;
|
|
22
|
-
}
|
|
23
|
-
function injectTemplates(pwd, routes, htmlTemplatePromise) {
|
|
24
|
-
return async (c, next) => {
|
|
25
|
-
if (routes && !c.get("templates")) {
|
|
26
|
-
const templates = await (htmlTemplatePromise || getHtmlTemplates(pwd, routes));
|
|
27
|
-
c.set("templates", templates);
|
|
28
|
-
}
|
|
29
|
-
await next();
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const loadBundle = async (filepath, logger) => {
|
|
33
|
-
if (!await fs.pathExists(filepath)) {
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const module = await compatibleRequire(filepath, false);
|
|
38
|
-
return module;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
async function getServerManifest(pwd, routes, logger) {
|
|
45
|
-
const loaderBundles = {};
|
|
46
|
-
const renderBundles = {};
|
|
47
|
-
await Promise.all(routes.filter((route) => Boolean(route.bundle)).map(async (route) => {
|
|
48
|
-
const entryName = route.entryName || MAIN_ENTRY_NAME;
|
|
49
|
-
const renderBundlePath = path.join(pwd, route.bundle || "");
|
|
50
|
-
const loaderBundlePath = path.join(pwd, SERVER_BUNDLE_DIRECTORY, `${entryName}-server-loaders.js`);
|
|
51
|
-
const renderBundle = await loadBundle(renderBundlePath, logger);
|
|
52
|
-
const loaderBundle = await loadBundle(loaderBundlePath, logger);
|
|
53
|
-
renderBundle && (renderBundles[entryName] = renderBundle);
|
|
54
|
-
loaderBundle && (loaderBundles[entryName] = (loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules) ? await (loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules()) : loaderBundle);
|
|
55
|
-
}));
|
|
56
|
-
const loadableUri = path.join(pwd, LOADABLE_STATS_FILE);
|
|
57
|
-
const loadableStats = await compatibleRequire(loadableUri).catch((_) => ({}));
|
|
58
|
-
const routesManifestUri = path.join(pwd, ROUTE_MANIFEST_FILE);
|
|
59
|
-
const routeManifest = await compatibleRequire(routesManifestUri).catch((_) => ({}));
|
|
60
|
-
const nestedRoutesJsonPath = path.join(pwd, NESTED_ROUTE_SPEC_FILE);
|
|
61
|
-
const nestedRoutesJson = await compatibleRequire(nestedRoutesJsonPath).catch((_) => ({}));
|
|
62
|
-
return {
|
|
63
|
-
loaderBundles,
|
|
64
|
-
renderBundles,
|
|
65
|
-
loadableStats,
|
|
66
|
-
routeManifest,
|
|
67
|
-
nestedRoutesJson
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function injectServerManifest(pwd, routes, manifestPromise) {
|
|
71
|
-
return async (c, next) => {
|
|
72
|
-
if (routes && !c.get("serverManifest")) {
|
|
73
|
-
const logger = c.get("logger");
|
|
74
|
-
const serverManifest = await (manifestPromise || getServerManifest(pwd, routes, logger));
|
|
75
|
-
c.set("serverManifest", serverManifest);
|
|
76
|
-
}
|
|
77
|
-
await next();
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
async function getRscServerManifest(pwd) {
|
|
81
|
-
const rscServerManifest = await compatibleRequire(path.join(pwd, "bundles", "react-server-manifest.json")).catch((_) => void 0);
|
|
82
|
-
return rscServerManifest;
|
|
83
|
-
}
|
|
84
|
-
async function getClientManifest(pwd) {
|
|
85
|
-
const rscClientManifest = await compatibleRequire(path.join(pwd, "react-client-manifest.json")).catch((_) => void 0);
|
|
86
|
-
return rscClientManifest;
|
|
87
|
-
}
|
|
88
|
-
async function getRscSSRManifest(pwd) {
|
|
89
|
-
const rscSSRManifest = await compatibleRequire(path.join(pwd, "react-ssr-manifest.json")).catch((_) => void 0);
|
|
90
|
-
return rscSSRManifest;
|
|
91
|
-
}
|
|
92
|
-
const injectRscManifestPlugin = () => ({
|
|
93
|
-
name: "@modern-js/plugin-inject-rsc-manifest",
|
|
94
|
-
setup(api) {
|
|
95
|
-
return {
|
|
96
|
-
async prepare() {
|
|
97
|
-
var _config_server;
|
|
98
|
-
const { middlewares, distDirectory: pwd } = api.useAppContext();
|
|
99
|
-
const config = api.useConfigContext();
|
|
100
|
-
if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.rsc)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
middlewares.push({
|
|
104
|
-
name: "inject-rsc-manifest",
|
|
105
|
-
handler: async (c, next) => {
|
|
106
|
-
if (!c.get("rscServerManifest")) {
|
|
107
|
-
const rscServerManifest = await getRscServerManifest(pwd);
|
|
108
|
-
c.set("rscServerManifest", rscServerManifest);
|
|
109
|
-
}
|
|
110
|
-
if (!c.get("rscClientManifest")) {
|
|
111
|
-
const rscClientManifest = await getClientManifest(pwd);
|
|
112
|
-
c.set("rscClientManifest", rscClientManifest);
|
|
113
|
-
}
|
|
114
|
-
if (!c.get("rscSSRManifest")) {
|
|
115
|
-
const rscSSRManifest = await getRscSSRManifest(pwd);
|
|
116
|
-
c.set("rscSSRManifest", rscSSRManifest);
|
|
117
|
-
}
|
|
118
|
-
await next();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
const injectResourcePlugin = () => ({
|
|
126
|
-
name: "@modern-js/plugin-inject-resource",
|
|
127
|
-
setup(api) {
|
|
128
|
-
return {
|
|
129
|
-
async prepare() {
|
|
130
|
-
const { middlewares, routes, distDirectory: pwd } = api.useAppContext();
|
|
131
|
-
let htmlTemplatePromise;
|
|
132
|
-
let manifestPromise;
|
|
133
|
-
if (isProd()) {
|
|
134
|
-
manifestPromise = getServerManifest(pwd, routes || [], console);
|
|
135
|
-
htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
|
|
136
|
-
}
|
|
137
|
-
middlewares.push({
|
|
138
|
-
name: "inject-server-manifest",
|
|
139
|
-
handler: injectServerManifest(pwd, routes, manifestPromise)
|
|
140
|
-
});
|
|
141
|
-
middlewares.push({
|
|
142
|
-
name: "inject-html",
|
|
143
|
-
handler: injectTemplates(pwd, routes, htmlTemplatePromise)
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
export {
|
|
150
|
-
getClientManifest,
|
|
151
|
-
getHtmlTemplates,
|
|
152
|
-
getRscSSRManifest,
|
|
153
|
-
getRscServerManifest,
|
|
154
|
-
getServerManifest,
|
|
155
|
-
injectResourcePlugin,
|
|
156
|
-
injectRscManifestPlugin,
|
|
157
|
-
injectServerManifest,
|
|
158
|
-
injectTemplates
|
|
159
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
3
|
-
import { fs } from "@modern-js/utils";
|
|
4
|
-
import { getMimeType } from "hono/utils/mime";
|
|
5
|
-
import { sortRoutes } from "../../../utils";
|
|
6
|
-
const serverStaticPlugin = () => ({
|
|
7
|
-
name: "@modern-js/plugin-server-static",
|
|
8
|
-
setup(api) {
|
|
9
|
-
return {
|
|
10
|
-
prepare() {
|
|
11
|
-
const { middlewares, distDirectory: pwd, routes } = api.useAppContext();
|
|
12
|
-
const config = api.useConfigContext();
|
|
13
|
-
const serverStaticMiddleware = createStaticMiddleware({
|
|
14
|
-
pwd,
|
|
15
|
-
routes,
|
|
16
|
-
output: config.output || {},
|
|
17
|
-
html: config.html || {}
|
|
18
|
-
});
|
|
19
|
-
middlewares.push({
|
|
20
|
-
name: "server-static",
|
|
21
|
-
handler: serverStaticMiddleware
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
function createPublicMiddleware({ pwd, routes }) {
|
|
28
|
-
return async (c, next) => {
|
|
29
|
-
const route = matchPublicRoute(c.req, routes);
|
|
30
|
-
if (route) {
|
|
31
|
-
const { entryPath } = route;
|
|
32
|
-
const filename = path.join(pwd, entryPath);
|
|
33
|
-
const data = await fileReader.readFile(filename, "buffer");
|
|
34
|
-
const mimeType = getMimeType(filename);
|
|
35
|
-
if (data !== null) {
|
|
36
|
-
if (mimeType) {
|
|
37
|
-
c.header("Content-Type", mimeType);
|
|
38
|
-
}
|
|
39
|
-
Object.entries(route.responseHeaders || {}).forEach(([k, v]) => {
|
|
40
|
-
c.header(k, v);
|
|
41
|
-
});
|
|
42
|
-
return c.body(data, 200);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return await next();
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function matchPublicRoute(req, routes) {
|
|
49
|
-
for (const route of routes.sort(sortRoutes)) {
|
|
50
|
-
if (!route.isSSR && route.entryPath.startsWith("public") && req.path.startsWith(route.urlPath)) {
|
|
51
|
-
return route;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return void 0;
|
|
55
|
-
}
|
|
56
|
-
const extractPathname = (url) => {
|
|
57
|
-
try {
|
|
58
|
-
if (url.includes("://")) {
|
|
59
|
-
return new URL(url).pathname || "/";
|
|
60
|
-
}
|
|
61
|
-
if (url.startsWith("//")) {
|
|
62
|
-
return new URL(`http:${url}`).pathname || "/";
|
|
63
|
-
}
|
|
64
|
-
return url;
|
|
65
|
-
} catch (e) {
|
|
66
|
-
return url;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
function createStaticMiddleware(options) {
|
|
70
|
-
const { pwd, routes } = options;
|
|
71
|
-
const prefix = options.output.assetPrefix || "/";
|
|
72
|
-
const pathPrefix = extractPathname(prefix);
|
|
73
|
-
const { distPath: { css: cssPath, js: jsPath, media: mediaPath } = {} } = options.output;
|
|
74
|
-
const { favicon, faviconByEntries } = options.html;
|
|
75
|
-
const favicons = prepareFavicons(favicon, faviconByEntries);
|
|
76
|
-
const staticFiles = [
|
|
77
|
-
cssPath,
|
|
78
|
-
jsPath,
|
|
79
|
-
mediaPath
|
|
80
|
-
].filter((v) => Boolean(v));
|
|
81
|
-
const staticReg = [
|
|
82
|
-
"static/",
|
|
83
|
-
"upload/",
|
|
84
|
-
...staticFiles
|
|
85
|
-
];
|
|
86
|
-
const iconReg = [
|
|
87
|
-
"favicon.ico",
|
|
88
|
-
"icon.png",
|
|
89
|
-
...favicons
|
|
90
|
-
];
|
|
91
|
-
const regPrefix = pathPrefix.endsWith("/") ? pathPrefix : `${pathPrefix}/`;
|
|
92
|
-
const staticPathRegExp = new RegExp(`^${regPrefix}(${[
|
|
93
|
-
...staticReg,
|
|
94
|
-
...iconReg
|
|
95
|
-
].join("|")})`);
|
|
96
|
-
return async (c, next) => {
|
|
97
|
-
const pageRoute = c.get("route");
|
|
98
|
-
const pathname = c.req.path;
|
|
99
|
-
if (pageRoute && path.extname(pathname) === "") {
|
|
100
|
-
return next();
|
|
101
|
-
}
|
|
102
|
-
const hit = staticPathRegExp.test(pathname);
|
|
103
|
-
if (hit) {
|
|
104
|
-
const filepath = path.join(pwd, pathname.replace(pathPrefix, () => ""));
|
|
105
|
-
if (!await fs.pathExists(filepath)) {
|
|
106
|
-
return next();
|
|
107
|
-
}
|
|
108
|
-
const mimeType = getMimeType(filepath);
|
|
109
|
-
if (mimeType) {
|
|
110
|
-
c.header("Content-Type", mimeType);
|
|
111
|
-
}
|
|
112
|
-
const stat = await fs.lstat(filepath);
|
|
113
|
-
const { size } = stat;
|
|
114
|
-
const chunk = await fileReader.readFileFromSystem(filepath, "buffer");
|
|
115
|
-
c.header("Content-Length", String(size));
|
|
116
|
-
return c.body(chunk, 200);
|
|
117
|
-
} else {
|
|
118
|
-
return createPublicMiddleware({
|
|
119
|
-
pwd,
|
|
120
|
-
routes: routes || []
|
|
121
|
-
})(c, next);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const prepareFavicons = (favicon, faviconByEntries) => {
|
|
126
|
-
const faviconNames = [];
|
|
127
|
-
if (favicon && typeof favicon === "string") {
|
|
128
|
-
faviconNames.push(favicon.substring(favicon.lastIndexOf("/") + 1));
|
|
129
|
-
}
|
|
130
|
-
if (faviconByEntries) {
|
|
131
|
-
Object.keys(faviconByEntries).forEach((f) => {
|
|
132
|
-
const curFavicon = faviconByEntries[f];
|
|
133
|
-
if (curFavicon) {
|
|
134
|
-
faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf("/") + 1));
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
return faviconNames;
|
|
139
|
-
};
|
|
140
|
-
export {
|
|
141
|
-
createPublicMiddleware,
|
|
142
|
-
createStaticMiddleware,
|
|
143
|
-
serverStaticPlugin
|
|
144
|
-
};
|