@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.100 → 3.5.0-ultramodern.102
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/bin/modern-bundle-docs.js +7 -0
- package/dist/cjs/bundleDocs.js +114 -0
- package/dist/esm/bundleDocs.mjs +62 -0
- package/dist/esm-node/bundleDocs.mjs +63 -0
- package/dist/types/bundleDocs.d.ts +20 -0
- package/docs/apis/app/{commands.mdx → commands.md} +35 -9
- package/docs/apis/app/hooks/api/{lambda.mdx → lambda.md} +2 -6
- package/docs/apis/app/hooks/config/{favicon.mdx → favicon.md} +1 -6
- package/docs/apis/app/hooks/config/{html.mdx → html.md} +1 -5
- package/docs/apis/app/hooks/config/{icon.mdx → icon.md} +1 -6
- package/docs/apis/app/hooks/config/{mock.mdx → mock.md} +1 -5
- package/docs/apis/app/hooks/config/{public.mdx → public.md} +0 -4
- package/docs/apis/app/hooks/config/{upload.mdx → upload.md} +3 -7
- package/docs/apis/app/hooks/{modern-config.mdx → modern-config.md} +1 -5
- package/docs/apis/app/hooks/server/{server.mdx → server.md} +1 -6
- package/docs/apis/app/hooks/{shared.mdx → shared.md} +0 -4
- package/docs/apis/app/hooks/src/{app.mdx → app.md} +2 -2
- package/docs/apis/app/hooks/src/{entry.mdx → entry.md} +1 -6
- package/docs/apis/app/hooks/src/{entry.server.mdx → entry.server.md} +0 -5
- package/docs/apis/app/hooks/src/{modern.runtime.mdx → modern.runtime.md} +1 -5
- package/docs/apis/app/hooks/src/{routes.mdx → routes.md} +3 -7
- package/docs/apis/app/hooks/src/{server.mdx → server.md} +1 -5
- package/docs/apis/app/runtime/bff/{use-backend-context.mdx → use-backend-context.md} +0 -3
- package/docs/apis/app/runtime/core/{create-root.mdx → create-root.md} +0 -3
- package/docs/apis/app/runtime/core/{render.mdx → render.md} +1 -4
- package/docs/apis/app/runtime/core/{runtime-context.mdx → runtime-context.md} +0 -4
- package/docs/apis/app/runtime/router/{router.mdx → router.md} +1 -6
- package/docs/apis/app/runtime/ssr/{no-ssr.mdx → no-ssr.md} +0 -3
- package/docs/apis/app/runtime/ssr/{renderStreaming.mdx → renderStreaming.md} +0 -4
- package/docs/apis/app/runtime/ssr/{renderString.mdx → renderString.md} +0 -4
- package/docs/apis/app/runtime/ssr/{requestHandler.mdx → requestHandler.md} +0 -4
- package/docs/apis/app/runtime/utility/{css-in-js.mdx → css-in-js.md} +0 -4
- package/docs/apis/app/runtime/utility/{head.mdx → head.md} +0 -3
- package/docs/apis/app/runtime/utility/{loadable.mdx → loadable.md} +0 -3
- package/docs/community/blog/2022-0708-updates.md +91 -0
- package/docs/community/blog/2022-0910-updates.md +76 -0
- package/docs/community/blog/overview.md +63 -0
- package/docs/community/blog/v2-release-note.md +238 -0
- package/docs/community/blog/v3-release-note.md +622 -0
- package/docs/community/contributing-guide.md +252 -0
- package/docs/community/releases.md +23 -0
- package/docs/community/showcase.md +24 -0
- package/docs/community/team.md +14 -0
- package/docs/configure/app/bff/{cross-project.mdx → cross-project.md} +4 -8
- package/docs/configure/app/bff/{effect.mdx → effect.md} +3 -7
- package/docs/configure/app/bff/{prefix.mdx → prefix.md} +3 -7
- package/docs/configure/app/bff/{runtime-framework.mdx → runtime-framework.md} +3 -7
- package/docs/configure/app/{builder-plugins.mdx → builder-plugins.md} +4 -8
- package/docs/configure/app/dev/{asset-prefix.mdx → asset-prefix.md} +4 -9
- package/docs/configure/app/dev/{before-start-url.mdx → before-start-url.md} +0 -4
- package/docs/configure/app/dev/{client.mdx → client.md} +3 -7
- package/docs/configure/app/dev/hmr.md +10 -0
- package/docs/configure/app/dev/{host.mdx → host.md} +0 -4
- package/docs/configure/app/dev/{https.mdx → https.md} +0 -4
- package/docs/configure/app/dev/{lazy-compilation.mdx → lazy-compilation.md} +2 -8
- package/docs/configure/app/dev/live-reload.md +10 -0
- package/docs/configure/app/dev/{mock-dir.mdx → mock-dir.md} +0 -4
- package/docs/configure/app/dev/progress-bar.md +19 -0
- package/docs/configure/app/dev/{server.mdx → server.md} +0 -4
- package/docs/configure/app/dev/{setup-middlewares.mdx → setup-middlewares.md} +3 -7
- package/docs/configure/app/dev/{start-url.mdx → start-url.md} +0 -5
- package/docs/configure/app/dev/{watch-files.mdx → watch-files.md} +3 -7
- package/docs/configure/app/dev/{write-to-disk.mdx → write-to-disk.md} +3 -7
- package/docs/configure/app/experiments/{source-build.mdx → source-build.md} +1 -3
- package/docs/configure/app/html/{app-icon.mdx → app-icon.md} +3 -7
- package/docs/configure/app/html/{crossorigin.mdx → crossorigin.md} +3 -7
- package/docs/configure/app/html/{favicon.mdx → favicon.md} +3 -7
- package/docs/configure/app/html/inject.md +10 -0
- package/docs/configure/app/html/{meta.mdx → meta.md} +3 -7
- package/docs/configure/app/html/{mount-id.mdx → mount-id.md} +3 -7
- package/docs/configure/app/html/output-structure.md +10 -0
- package/docs/configure/app/html/script-loading.md +10 -0
- package/docs/configure/app/html/{tags.mdx → tags.md} +3 -7
- package/docs/configure/app/html/{template-parameters.mdx → template-parameters.md} +3 -7
- package/docs/configure/app/html/template.md +10 -0
- package/docs/configure/app/html/title.md +18 -0
- package/docs/configure/app/output/asset-prefix.md +11 -0
- package/docs/configure/app/output/{assets-retry.mdx → assets-retry.md} +1 -5
- package/docs/configure/app/output/{charset.mdx → charset.md} +3 -7
- package/docs/configure/app/output/{clean-dist-path.mdx → clean-dist-path.md} +0 -4
- package/docs/configure/app/output/{convert-to-rem.mdx → convert-to-rem.md} +12 -16
- package/docs/configure/app/output/{copy.mdx → copy.md} +3 -7
- package/docs/configure/app/output/{css-modules.mdx → css-modules.md} +3 -7
- package/docs/configure/app/output/{data-uri-limit.mdx → data-uri-limit.md} +3 -7
- package/docs/configure/app/output/{disable-css-module-extension.mdx → disable-css-module-extension.md} +3 -7
- package/docs/configure/app/output/{disable-inline-runtime-chunk.mdx → disable-inline-runtime-chunk.md} +0 -4
- package/docs/configure/app/output/{disable-svgr.mdx → disable-svgr.md} +0 -4
- package/docs/configure/app/output/{disable-ts-checker.mdx → disable-ts-checker.md} +0 -4
- package/docs/configure/app/output/{dist-path.mdx → dist-path.md} +3 -11
- package/docs/configure/app/output/{enable-asset-manifest.mdx → enable-asset-manifest.md} +0 -4
- package/docs/configure/app/output/{enable-css-module-tsdeclaration.mdx → enable-css-module-tsdeclaration.md} +0 -4
- package/docs/configure/app/output/{enable-inline-route-manifests.mdx → enable-inline-route-manifests.md} +0 -4
- package/docs/configure/app/output/{externals.mdx → externals.md} +3 -7
- package/docs/configure/app/output/filename-hash.md +10 -0
- package/docs/configure/app/output/{filename.mdx → filename.md} +3 -7
- package/docs/configure/app/output/inject-styles.md +10 -0
- package/docs/configure/app/output/{inline-scripts.mdx → inline-scripts.md} +4 -8
- package/docs/configure/app/output/{inline-styles.mdx → inline-styles.md} +4 -8
- package/docs/configure/app/output/{legal-comments.mdx → legal-comments.md} +3 -7
- package/docs/configure/app/output/{minify.mdx → minify.md} +3 -7
- package/docs/configure/app/output/{override-browserslist.mdx → override-browserslist.md} +4 -8
- package/docs/configure/app/output/polyfill.md +12 -0
- package/docs/configure/app/output/{source-map.mdx → source-map.md} +3 -7
- package/docs/configure/app/output/{split-route-chunks.mdx → split-route-chunks.md} +0 -4
- package/docs/configure/app/output/{ssg.mdx → ssg.md} +3 -7
- package/docs/configure/app/output/{ssgByEntries.mdx → ssgByEntries.md} +1 -4
- package/docs/configure/app/output/{svg-default-export.mdx → svg-default-export.md} +0 -4
- package/docs/configure/app/output/{temp-dir.mdx → temp-dir.md} +0 -4
- package/docs/configure/app/performance/{build-cache.mdx → build-cache.md} +3 -7
- package/docs/configure/app/performance/{chunk-split.mdx → chunk-split.md} +3 -7
- package/docs/configure/app/performance/{dns-prefetch.mdx → dns-prefetch.md} +3 -7
- package/docs/configure/app/performance/preconnect.md +16 -0
- package/docs/configure/app/performance/{prefetch.mdx → prefetch.md} +3 -7
- package/docs/configure/app/performance/{preload.mdx → preload.md} +3 -7
- package/docs/configure/app/performance/{print-file-size.mdx → print-file-size.md} +3 -7
- package/docs/configure/app/performance/profile.md +10 -0
- package/docs/configure/app/performance/remove-console.md +10 -0
- package/docs/configure/app/performance/remove-moment-locale.md +10 -0
- package/docs/configure/app/performance/{rsdoctor.mdx → rsdoctor.md} +0 -4
- package/docs/configure/app/{plugins.mdx → plugins.md} +4 -4
- package/docs/configure/app/resolve/{alias-strategy.mdx → alias-strategy.md} +3 -7
- package/docs/configure/app/resolve/alias.md +9 -0
- package/docs/configure/app/resolve/{condition-names.mdx → condition-names.md} +3 -8
- package/docs/configure/app/resolve/{dedupe.mdx → dedupe.md} +3 -7
- package/docs/configure/app/resolve/{extensions.mdx → extensions.md} +3 -8
- package/docs/configure/app/runtime/{0-intro.mdx → 0-intro.md} +1 -4
- package/docs/configure/app/runtime/{plugins.mdx → plugins.md} +1 -1
- package/docs/configure/app/runtime/{router.mdx → router.md} +3 -7
- package/docs/configure/app/security/{check-syntax.mdx → check-syntax.md} +0 -4
- package/docs/configure/app/security/{nonce.mdx → nonce.md} +3 -7
- package/docs/configure/app/security/{sri.mdx → sri.md} +0 -4
- package/docs/configure/app/server/{base-url.mdx → base-url.md} +0 -4
- package/docs/configure/app/server/{port.mdx → port.md} +3 -7
- package/docs/configure/app/server/{public-routes.mdx → public-routes.md} +0 -4
- package/docs/configure/app/server/{routes.mdx → routes.md} +1 -5
- package/docs/configure/app/server/{rsc.mdx → rsc.md} +2 -6
- package/docs/configure/app/server/{ssr-by-entries.mdx → ssr-by-entries.md} +1 -5
- package/docs/configure/app/server/ssr.md +80 -0
- package/docs/configure/app/server/{tsconfig-path.mdx → tsconfig-path.md} +0 -4
- package/docs/configure/app/source/{alias-strategy.mdx → alias-strategy.md} +4 -8
- package/docs/configure/app/source/{alias.mdx → alias.md} +4 -8
- package/docs/configure/app/source/{config-dir.mdx → config-dir.md} +1 -5
- package/docs/configure/app/source/{decorators.mdx → decorators.md} +0 -4
- package/docs/configure/app/source/{define.mdx → define.md} +3 -7
- package/docs/configure/app/source/{disable-default-entries.mdx → disable-default-entries.md} +2 -6
- package/docs/{components/module-federation.mdx → configure/app/source/enable-async-entry.md} +47 -0
- package/docs/configure/app/source/{enable-async-pre-entry.mdx → enable-async-pre-entry.md} +0 -4
- package/docs/configure/app/source/{entries-dir.mdx → entries-dir.md} +0 -4
- package/docs/configure/app/source/{entries.mdx → entries.md} +1 -5
- package/docs/configure/app/source/{exclude.mdx → exclude.md} +4 -8
- package/docs/configure/app/source/{global-vars.mdx → global-vars.md} +0 -4
- package/docs/configure/app/source/{include.mdx → include.md} +4 -8
- package/docs/configure/app/source/{main-entry-name.mdx → main-entry-name.md} +0 -4
- package/docs/configure/app/source/{pre-entry.mdx → pre-entry.md} +3 -7
- package/docs/configure/app/source/{react-compiler.mdx → react-compiler.md} +0 -4
- package/docs/configure/app/source/{transform-import.mdx → transform-import.md} +3 -7
- package/docs/configure/app/{split-chunks.mdx → split-chunks.md} +3 -3
- package/docs/configure/app/tools/{autoprefixer.mdx → autoprefixer.md} +0 -4
- package/docs/configure/app/tools/{bundler-chain.mdx → bundler-chain.md} +0 -4
- package/docs/configure/app/tools/{css-extract.mdx → css-extract.md} +3 -7
- package/docs/configure/app/tools/{css-loader.mdx → css-loader.md} +3 -7
- package/docs/configure/app/tools/{dev-server.mdx → dev-server.md} +0 -4
- package/docs/configure/app/tools/{html-plugin.mdx → html-plugin.md} +3 -7
- package/docs/configure/app/tools/{less.mdx → less.md} +0 -4
- package/docs/configure/app/tools/{lightningcss-loader.mdx → lightningcss-loader.md} +3 -7
- package/docs/configure/app/tools/{minify-css.mdx → minify-css.md} +0 -4
- package/docs/configure/app/tools/{postcss.mdx → postcss.md} +3 -7
- package/docs/configure/app/tools/rspack.md +10 -0
- package/docs/configure/app/tools/{sass.mdx → sass.md} +0 -4
- package/docs/configure/app/tools/style-loader.md +10 -0
- package/docs/configure/app/tools/{swc.mdx → swc.md} +4 -8
- package/docs/configure/app/tools/{ts-checker.mdx → ts-checker.md} +20 -7
- package/docs/configure/app/{usage.mdx → usage.md} +1 -1
- package/docs/guides/advanced-features/bff/{cross-project.mdx → cross-project.md} +1 -2
- package/docs/guides/advanced-features/bff/{data-platform.mdx → data-platform.md} +0 -4
- package/docs/guides/advanced-features/bff/{extend-server.mdx → extend-server.md} +1 -1
- package/docs/guides/advanced-features/bff/frameworks.md +243 -0
- package/docs/guides/advanced-features/bff/{function.mdx → function.md} +60 -7
- package/docs/guides/advanced-features/bff/{operators.mdx → operators.md} +2 -77
- package/docs/{components/bff-upload.mdx → guides/advanced-features/bff/upload.md} +4 -0
- package/docs/guides/advanced-features/{bff.mdx → bff.md} +0 -4
- package/docs/guides/advanced-features/{build-performance.mdx → build-performance.md} +3 -7
- package/docs/guides/advanced-features/{compatibility.mdx → compatibility.md} +54 -15
- package/docs/guides/advanced-features/international/{advanced.mdx → advanced.md} +0 -4
- package/docs/guides/advanced-features/international/{api.mdx → api.md} +16 -20
- package/docs/guides/advanced-features/international/{best-practices.mdx → best-practices.md} +0 -4
- package/docs/guides/advanced-features/international/configuration.md +228 -0
- package/docs/guides/advanced-features/international/{locale-detection.mdx → locale-detection.md} +25 -29
- package/docs/guides/advanced-features/international/{quick-start.mdx → quick-start.md} +29 -13
- package/docs/guides/advanced-features/international/{resource-loading.mdx → resource-loading.md} +11 -15
- package/docs/guides/advanced-features/international/{routing.mdx → routing.md} +12 -16
- package/docs/guides/advanced-features/international.md +27 -0
- package/docs/guides/advanced-features/{low-level.mdx → low-level.md} +17 -21
- package/docs/guides/advanced-features/page-performance/{code-split.mdx → code-split.md} +2 -6
- package/docs/guides/advanced-features/page-performance/{inline-assets.mdx → inline-assets.md} +3 -7
- package/docs/guides/advanced-features/page-performance/{optimize-bundle.mdx → optimize-bundle.md} +4 -8
- package/docs/{components/internal-logger.mdx → guides/advanced-features/server-monitor/logger.md} +16 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
- package/docs/guides/advanced-features/server-monitor/{monitors.mdx → monitors.md} +3 -3
- package/docs/guides/advanced-features/{source-build.mdx → source-build.md} +1 -5
- package/docs/guides/advanced-features/{web-server.mdx → web-server.md} +1 -9
- package/docs/guides/basic-features/{alias.mdx → alias.md} +3 -7
- package/docs/guides/basic-features/css/{css-in-js.mdx → css-in-js.md} +12 -9
- package/docs/guides/basic-features/css/{css-modules.mdx → css-modules.md} +3 -3
- package/docs/guides/basic-features/css/{css.mdx → css.md} +2 -6
- package/docs/guides/basic-features/data/{data-cache.mdx → data-cache.md} +1 -6
- package/docs/guides/basic-features/data/{data-fetch.mdx → data-fetch.md} +4 -8
- package/docs/guides/basic-features/data/{data-write.mdx → data-write.md} +6 -9
- package/docs/guides/basic-features/debug/{mock.mdx → mock.md} +1 -5
- package/docs/guides/basic-features/debug/{proxy.mdx → proxy.md} +1 -5
- package/docs/guides/basic-features/debug/{using-storybook.mdx → using-storybook.md} +20 -8
- package/docs/guides/basic-features/{deploy.mdx → deploy.md} +23 -13
- package/docs/guides/basic-features/{env-vars.mdx → env-vars.md} +8 -12
- package/docs/guides/basic-features/{html.mdx → html.md} +3 -7
- package/docs/guides/basic-features/{output-files.mdx → output-files.md} +6 -10
- package/docs/guides/basic-features/render/{before-render.mdx → before-render.md} +1 -1
- package/docs/guides/basic-features/render/overview.md +47 -0
- package/docs/guides/basic-features/render/{rsc.mdx → rsc.md} +12 -20
- package/docs/guides/basic-features/render/{ssg.mdx → ssg.md} +71 -10
- package/docs/guides/basic-features/render/{ssr-cache.mdx → ssr-cache.md} +5 -5
- package/docs/guides/basic-features/render/{ssr.mdx → ssr.md} +10 -12
- package/docs/guides/basic-features/render/{streaming-ssr.mdx → streaming-ssr.md} +5 -8
- package/docs/guides/basic-features/routes/{config-routes.mdx → config-routes.md} +10 -11
- package/docs/guides/basic-features/routes/{routes.mdx → routes.md} +8 -16
- package/docs/guides/basic-features/static-assets/{json-files.mdx → json-files.md} +0 -4
- package/docs/guides/basic-features/static-assets/{svg-assets.mdx → svg-assets.md} +3 -7
- package/docs/guides/basic-features/static-assets/{wasm-assets.mdx → wasm-assets.md} +1 -5
- package/docs/guides/basic-features/{static-assets.mdx → static-assets.md} +10 -14
- package/docs/guides/basic-features/testing/{playwright.mdx → playwright.md} +12 -3
- package/docs/guides/basic-features/testing/{rstest.mdx → rstest.md} +70 -11
- package/docs/guides/concept/{builder.mdx → builder.md} +3 -26
- package/docs/guides/concept/{entries.mdx → entries.md} +11 -17
- package/docs/guides/concept/{server.mdx → server.md} +3 -3
- package/docs/guides/get-started/{ai-coding-agents.mdx → ai-coding-agents.md} +4 -9
- package/docs/guides/get-started/glossary.md +63 -0
- package/docs/guides/get-started/{introduction.mdx → introduction.md} +1 -6
- package/docs/guides/get-started/quick-start.md +269 -0
- package/docs/guides/get-started/{tech-stack.mdx → tech-stack.md} +9 -15
- package/docs/guides/get-started/{ultramodern.mdx → ultramodern.md} +19 -24
- package/docs/guides/get-started/{upgrade.mdx → upgrade.md} +21 -12
- package/docs/guides/topic-detail/module-federation/{application.mdx → application.md} +3 -3
- package/docs/guides/topic-detail/module-federation/{deploy.mdx → deploy.md} +2 -2
- package/docs/guides/topic-detail/module-federation/{i18n.mdx → i18n.md} +14 -14
- package/docs/guides/topic-detail/module-federation/{introduce.mdx → introduce.md} +2 -3
- package/docs/guides/topic-detail/module-federation/{ssr.mdx → ssr.md} +12 -7
- package/docs/guides/topic-detail/module-federation/{usage.mdx → usage.md} +20 -3
- package/docs/guides/troubleshooting/{builder.mdx → builder.md} +10 -14
- package/docs/guides/troubleshooting/{cli.mdx → cli.md} +0 -4
- package/docs/guides/troubleshooting/{dependencies.mdx → dependencies.md} +7 -11
- package/docs/guides/troubleshooting/{hmr.mdx → hmr.md} +5 -9
- package/docs/guides/upgrade/{config.mdx → config.md} +8 -5
- package/docs/guides/upgrade/{entry.mdx → entry.md} +6 -6
- package/docs/guides/upgrade/{other.mdx → other.md} +8 -8
- package/docs/guides/upgrade/{overview.mdx → overview.md} +4 -4
- package/docs/guides/upgrade/{tailwindcss.mdx → tailwindcss.md} +0 -1
- package/docs/guides/upgrade/web-server.md +11 -11
- package/docs/index.md +33 -4
- package/docs/llms.txt +290 -0
- package/docs/plugin/cli-plugins/api.md +573 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +152 -0
- package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
- package/docs/plugin/official/cli-plugins.md +4 -0
- package/docs/plugin/plugin-system.md +238 -0
- package/docs/plugin/runtime-plugins/api.md +194 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +209 -0
- package/docs/plugin/server-plugins/life-cycle.md +13 -0
- package/docs/tutorials/examples/csr-auth.md +9 -0
- package/docs/tutorials/foundations/introduction.md +16 -0
- package/package.json +32 -14
- package/docs/_nav.json +0 -36
- package/docs/apis/_meta.json +0 -13
- package/docs/apis/app/hooks/_meta.json +0 -28
- package/docs/apis/app/hooks/config/_meta.json +0 -1
- package/docs/apis/app/runtime/_meta.json +0 -32
- package/docs/components/auto-upgrade.mdx +0 -0
- package/docs/components/build-output.mdx +0 -45
- package/docs/components/bundler.mdx +0 -3
- package/docs/components/convention-routing-motivation.mdx +0 -0
- package/docs/components/debug-app.mdx +0 -15
- package/docs/components/default-browserslist.mdx +0 -7
- package/docs/components/deploy-command.mdx +0 -14
- package/docs/components/deploy.mdx +0 -1
- package/docs/components/enable-bff-caution.mdx +0 -3
- package/docs/components/enable-bff.mdx +0 -56
- package/docs/components/enable-ssg.mdx +0 -49
- package/docs/components/entry-mode.mdx +0 -0
- package/docs/components/entry-scan-logic.mdx +0 -7
- package/docs/components/extend-bff-function.mdx +0 -3
- package/docs/components/hono.mdx +0 -120
- package/docs/components/init-app.mdx +0 -93
- package/docs/components/init-rspack-app.mdx +0 -5
- package/docs/components/internal-metrics.mdx +0 -20
- package/docs/components/international/custom-instance-code.mdx +0 -16
- package/docs/components/international/init-options-desc.mdx +0 -1
- package/docs/components/international/install-command.mdx +0 -10
- package/docs/components/international/instance-code.mdx +0 -16
- package/docs/components/international/introduce.mdx +0 -5
- package/docs/components/international/platform-support.mdx +0 -0
- package/docs/components/language-config.mdx +0 -9
- package/docs/components/micro-frontend.mdx +0 -6
- package/docs/components/micro-master-manifest-config.mdx +0 -15
- package/docs/components/micro-runtime-config.mdx +0 -17
- package/docs/components/new-entry-tooltip.mdx +0 -0
- package/docs/components/nodeVersion.mdx +0 -28
- package/docs/components/other-plugins.mdx +0 -0
- package/docs/components/output-asset-prefix-extend.mdx +0 -0
- package/docs/components/output-distpath-warning.mdx +0 -0
- package/docs/components/output-polyfill-extend.mdx +0 -1
- package/docs/components/prerequisites.mdx +0 -18
- package/docs/components/release-note.mdx +0 -1
- package/docs/components/routes-practice.mdx +0 -0
- package/docs/components/rsbuild-config-tooltip.mdx +0 -5
- package/docs/components/rsbuild.mdx +0 -3
- package/docs/components/rsc-deploy-tip.mdx +0 -1
- package/docs/components/rspack.mdx +0 -3
- package/docs/components/rspackTip.mdx +0 -7
- package/docs/components/runtime-cli-config.mdx +0 -0
- package/docs/components/serve-command.mdx +0 -22
- package/docs/components/ssr-monitor.mdx +0 -3
- package/docs/components/stream-ssr-performance.mdx +0 -0
- package/docs/components/swc.mdx +0 -3
- package/docs/components/tech-stack-node-framework.mdx +0 -1
- package/docs/components/turtorials-example-list.mdx +0 -2
- package/docs/components/ua-polyfill.mdx +0 -44
- package/docs/components/upgrade-browserslist.mdx +0 -0
- package/docs/components/upgrade-config-deploy.mdx +0 -0
- package/docs/components/upgrade-faq.mdx +0 -0
- package/docs/configure/_meta.json +0 -78
- package/docs/configure/app/dev/hmr.mdx +0 -14
- package/docs/configure/app/dev/live-reload.mdx +0 -14
- package/docs/configure/app/dev/progress-bar.mdx +0 -23
- package/docs/configure/app/html/inject.mdx +0 -14
- package/docs/configure/app/html/output-structure.mdx +0 -14
- package/docs/configure/app/html/script-loading.mdx +0 -14
- package/docs/configure/app/html/template.mdx +0 -14
- package/docs/configure/app/html/title.mdx +0 -22
- package/docs/configure/app/output/asset-prefix.mdx +0 -18
- package/docs/configure/app/output/filename-hash.mdx +0 -14
- package/docs/configure/app/output/inject-styles.mdx +0 -14
- package/docs/configure/app/output/polyfill.mdx +0 -18
- package/docs/configure/app/performance/preconnect.mdx +0 -20
- package/docs/configure/app/performance/profile.mdx +0 -14
- package/docs/configure/app/performance/remove-console.mdx +0 -14
- package/docs/configure/app/performance/remove-moment-locale.mdx +0 -14
- package/docs/configure/app/resolve/alias.mdx +0 -13
- package/docs/configure/app/server/ssr.mdx +0 -85
- package/docs/configure/app/source/enable-async-entry.mdx +0 -54
- package/docs/configure/app/tools/rspack.mdx +0 -14
- package/docs/configure/app/tools/style-loader.mdx +0 -14
- package/docs/guides/_meta.json +0 -37
- package/docs/guides/advanced-features/_meta.json +0 -32
- package/docs/guides/advanced-features/bff/_meta.json +0 -10
- package/docs/guides/advanced-features/bff/frameworks.mdx +0 -131
- package/docs/guides/advanced-features/bff/upload.mdx +0 -7
- package/docs/guides/advanced-features/international/_meta.json +0 -10
- package/docs/guides/advanced-features/international/configuration.mdx +0 -222
- package/docs/guides/advanced-features/international.mdx +0 -29
- package/docs/guides/advanced-features/page-performance/_meta.json +0 -1
- package/docs/guides/advanced-features/server-monitor/_meta.json +0 -1
- package/docs/guides/advanced-features/server-monitor/logger.mdx +0 -19
- package/docs/guides/advanced-features/server-monitor/metrics.mdx +0 -41
- package/docs/guides/basic-features/_meta.json +0 -49
- package/docs/guides/basic-features/css/_meta.json +0 -1
- package/docs/guides/basic-features/data/_meta.json +0 -1
- package/docs/guides/basic-features/debug/_meta.json +0 -1
- package/docs/guides/basic-features/render/_meta.json +0 -1
- package/docs/guides/basic-features/render/overview.mdx +0 -51
- package/docs/guides/basic-features/routes/_meta.json +0 -1
- package/docs/guides/basic-features/static-assets/_meta.json +0 -1
- package/docs/guides/basic-features/testing/_meta.json +0 -1
- package/docs/guides/concept/_meta.json +0 -1
- package/docs/guides/get-started/_meta.json +0 -9
- package/docs/guides/get-started/glossary.mdx +0 -63
- package/docs/guides/get-started/quick-start.mdx +0 -92
- package/docs/guides/topic-detail/_meta.json +0 -8
- package/docs/guides/topic-detail/module-federation/_meta.json +0 -1
- package/docs/guides/troubleshooting/_meta.json +0 -1
- package/docs/guides/upgrade/_meta.json +0 -1
- package/scripts/copy-main-doc.mjs +0 -50
- /package/docs/guides/advanced-features/bff/{sdk.mdx → sdk.md} +0 -0
- /package/docs/guides/advanced-features/page-performance/{react-compiler.mdx → react-compiler.md} +0 -0
- /package/docs/guides/basic-features/css/{tailwindcss.mdx → tailwindcss.md} +0 -0
- /package/docs/guides/basic-features/debug/{rsdoctor.mdx → rsdoctor.md} +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Runtime Framework
|
|
2
|
+
|
|
3
|
+
Modern.js supports two BFF runtime frameworks:
|
|
4
|
+
|
|
5
|
+
- `effect` (default): use [Effect HttpApi](https://effect.website/) runtime from `api/index`.
|
|
6
|
+
- `hono`: use file-convention BFF handlers from `api/lambda/**`.
|
|
7
|
+
|
|
8
|
+
`effect` and `hono` are strict runtime modes. There is no automatic fallback between them.
|
|
9
|
+
|
|
10
|
+
::::info
|
|
11
|
+
This page documents generic Modern.js runtime support. Generated UltraModern
|
|
12
|
+
workspaces always use the `effect` runtime with
|
|
13
|
+
`bff.effect.strictEffectApproach: true`. Add or change generated UltraModern
|
|
14
|
+
HTTP API work through `shared/api.ts` and `api/index.ts`; do not add
|
|
15
|
+
Hono/file-convention handlers, raw request parsing, or manual `Response`
|
|
16
|
+
construction inside those workspaces.
|
|
17
|
+
::::
|
|
18
|
+
|
|
19
|
+
## Switch to Effect runtime
|
|
20
|
+
|
|
21
|
+
```ts title="modern.config.ts"
|
|
22
|
+
import { bffPlugin } from '@modern-js/plugin-bff';
|
|
23
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
plugins: [bffPlugin()],
|
|
27
|
+
bff: {
|
|
28
|
+
runtimeFramework: 'effect',
|
|
29
|
+
effect: {
|
|
30
|
+
entry: './api/index',
|
|
31
|
+
strictEffectApproach: true,
|
|
32
|
+
openapi: {
|
|
33
|
+
path: '/openapi.json',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Define a shared Effect HttpApi contract (for type-safe client + server):
|
|
41
|
+
|
|
42
|
+
```ts title="shared/api.ts"
|
|
43
|
+
import {
|
|
44
|
+
HttpApi,
|
|
45
|
+
HttpApiEndpoint,
|
|
46
|
+
HttpApiGroup,
|
|
47
|
+
Schema,
|
|
48
|
+
} from '@modern-js/plugin-bff/effect-client';
|
|
49
|
+
|
|
50
|
+
export const bffApi = HttpApi.make('MyApi').add(
|
|
51
|
+
HttpApiGroup.make('hello').add(
|
|
52
|
+
HttpApiEndpoint.get('ping', '/ping', {
|
|
53
|
+
success: Schema.String,
|
|
54
|
+
}),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Implement your Effect API entry at `api/index.ts`:
|
|
60
|
+
|
|
61
|
+
```ts title="api/index.ts"
|
|
62
|
+
import {
|
|
63
|
+
Schema,
|
|
64
|
+
Effect,
|
|
65
|
+
HttpApiBuilder,
|
|
66
|
+
defineEffectBff,
|
|
67
|
+
Layer,
|
|
68
|
+
ServiceMap,
|
|
69
|
+
} from '@modern-js/plugin-bff/effect-server';
|
|
70
|
+
import { bffApi } from '../shared/api';
|
|
71
|
+
|
|
72
|
+
class GreetingUnavailableError extends Schema.TaggedError<GreetingUnavailableError>()(
|
|
73
|
+
'GreetingUnavailableError',
|
|
74
|
+
{
|
|
75
|
+
message: Schema.String,
|
|
76
|
+
},
|
|
77
|
+
) {}
|
|
78
|
+
|
|
79
|
+
class GreetingService extends ServiceMap.Service<GreetingService>()('GreetingService', {
|
|
80
|
+
make: Effect.succeed({
|
|
81
|
+
hello: Effect.fn('GreetingService.hello')(function* () {
|
|
82
|
+
if (Date.now() < 0) {
|
|
83
|
+
return yield* Effect.fail(
|
|
84
|
+
new GreetingUnavailableError({
|
|
85
|
+
message: 'Greeting service is unavailable',
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return yield* Effect.succeed('pong');
|
|
90
|
+
}),
|
|
91
|
+
}),
|
|
92
|
+
}) {
|
|
93
|
+
static readonly layer = Layer.effect(this, this.make);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const group = HttpApiBuilder.group(bffApi, 'hello', handlers =>
|
|
97
|
+
handlers.handle('ping', () =>
|
|
98
|
+
GreetingService.use(service => service.hello()).pipe(
|
|
99
|
+
Effect.catchTag('GreetingUnavailableError', error =>
|
|
100
|
+
Effect.succeed(error.message),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const layer = HttpApiBuilder.layer(bffApi).pipe(
|
|
107
|
+
Layer.provide(group),
|
|
108
|
+
Layer.provide(GreetingService.layer),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
export default defineEffectBff({ api: bffApi, layer });
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Call Effect endpoints from browser code via `@api/index`:
|
|
115
|
+
|
|
116
|
+
```ts title="src/routes/page.tsx"
|
|
117
|
+
import api from '@api/index';
|
|
118
|
+
|
|
119
|
+
const response = await api.client.hello.ping({});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The `api.client.*` surface is materialized by the BFF loader for `@api/index` imports. Do not import `api/index` directly and expect `client` to run in server code, scripts, or tests; direct entry imports expose the server runtime definition, and `client` is only a typed placeholder there.
|
|
123
|
+
|
|
124
|
+
### Getting Request Context
|
|
125
|
+
|
|
126
|
+
Sometimes in BFF functions, it's necessary to obtain the request context to handle more logic. In such cases, you can use `useHonoContext` to get it:
|
|
127
|
+
|
|
128
|
+
```ts title="api/lambda/hello.ts"
|
|
129
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
130
|
+
|
|
131
|
+
export const get = async () => {
|
|
132
|
+
const c = useHonoContext();
|
|
133
|
+
console.info(`access url: ${c.req.url}`);
|
|
134
|
+
return 'Hello Modern.js';
|
|
135
|
+
};
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
:::info
|
|
139
|
+
For more details, refer to [useHonoContext](/apis/app/runtime/bff/use-backend-context.md).
|
|
140
|
+
:::
|
|
141
|
+
|
|
142
|
+
### Getting Cookies
|
|
143
|
+
|
|
144
|
+
When getting cookies in BFF functions, you need to get the request context through `useHonoContext`, then use `c.req.header('cookie')` to get the Cookie string and parse it manually:
|
|
145
|
+
|
|
146
|
+
```ts title="api/lambda/cookies.ts"
|
|
147
|
+
import { Api, Get } from '@modern-js/plugin-bff/hono-server';
|
|
148
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
149
|
+
|
|
150
|
+
// Helper function to parse Cookie string
|
|
151
|
+
function parseCookies(
|
|
152
|
+
cookieHeader: string | undefined,
|
|
153
|
+
): Record<string, string> {
|
|
154
|
+
const cookies: Record<string, string> = {};
|
|
155
|
+
if (!cookieHeader) return cookies;
|
|
156
|
+
|
|
157
|
+
cookieHeader.split(';').forEach(cookie => {
|
|
158
|
+
const [name, ...rest] = cookie.trim().split('=');
|
|
159
|
+
if (name) {
|
|
160
|
+
cookies[name] = rest.join('=');
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return cookies;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const getCookies = Api(Get('/cookies'), async () => {
|
|
168
|
+
const c = useHonoContext();
|
|
169
|
+
const cookieHeader = c.req.header('cookie');
|
|
170
|
+
const cookies = parseCookies(cookieHeader);
|
|
171
|
+
const token = cookies.token;
|
|
172
|
+
const sessionId = cookies.sessionId;
|
|
173
|
+
return {
|
|
174
|
+
hasToken: !!token,
|
|
175
|
+
token: token || null,
|
|
176
|
+
sessionId: sessionId || null,
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
:::caution Note
|
|
182
|
+
The `c.req.cookie()` method does not exist in the current version. You need to use `c.req.header('cookie')` to get the Cookie string and parse it manually.
|
|
183
|
+
:::
|
|
184
|
+
|
|
185
|
+
### Defining BFF Functions
|
|
186
|
+
|
|
187
|
+
When using Hono as the runtime framework, you can define interfaces through [Api functions](/guides/advanced-features/bff/operators.md):
|
|
188
|
+
|
|
189
|
+
```ts title="api/lambda/user.ts"
|
|
190
|
+
import { Api, Get, Query } from '@modern-js/plugin-bff/hono-server';
|
|
191
|
+
import { z } from 'zod';
|
|
192
|
+
|
|
193
|
+
const QuerySchema = z.object({
|
|
194
|
+
id: z.string(),
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
export const getUser = Api(
|
|
198
|
+
Get('/user'),
|
|
199
|
+
Query(QuerySchema),
|
|
200
|
+
async ({ query }) => {
|
|
201
|
+
return {
|
|
202
|
+
id: query.id,
|
|
203
|
+
name: 'Modern.js',
|
|
204
|
+
email: 'modernjs@bytedance.com',
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
:::info
|
|
211
|
+
For more details about Api functions and operators, refer to [Creating Extensible BFF Functions](/guides/advanced-features/bff/operators.md).
|
|
212
|
+
:::
|
|
213
|
+
|
|
214
|
+
### Using Middleware
|
|
215
|
+
|
|
216
|
+
Hono supports a rich middleware ecosystem, and you can use middleware in BFF functions:
|
|
217
|
+
|
|
218
|
+
```ts title="api/lambda/user.ts"
|
|
219
|
+
import { Api, Get, Middleware } from '@modern-js/plugin-bff/hono-server';
|
|
220
|
+
|
|
221
|
+
export const getUser = Api(
|
|
222
|
+
Get('/user'),
|
|
223
|
+
Middleware(async (c, next) => {
|
|
224
|
+
// You can access Hono's Context in middleware
|
|
225
|
+
c.res.headers.set('X-Powered-By', 'Modern.js');
|
|
226
|
+
await next();
|
|
227
|
+
}),
|
|
228
|
+
async () => {
|
|
229
|
+
return {
|
|
230
|
+
name: 'Modern.js',
|
|
231
|
+
email: 'modernjs@bytedance.com',
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
:::info
|
|
238
|
+
For more details about middleware, refer to [Creating Extensible BFF Functions](/guides/advanced-features/bff/operators.md#middleware).
|
|
239
|
+
:::
|
|
240
|
+
|
|
241
|
+
### More Hono Documentation
|
|
242
|
+
|
|
243
|
+
For more detailed information about Hono, please refer to the [Hono official documentation](https://hono.dev/).
|
|
@@ -10,9 +10,62 @@ This invocation method is called **unified invocation**, where developers do not
|
|
|
10
10
|
|
|
11
11
|
## Enable BFF
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
To enable BFF functionality in a Modern.js project, follow these steps to modify the code:
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
1. Install BFF plugin dependencies
|
|
16
|
+
|
|
17
|
+
If the BFF plugin is not yet installed in your project, install it first:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @modern-js/plugin-bff
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
:::tip Version Consistency
|
|
24
|
+
Make sure the version of `@modern-js/plugin-bff` matches the version of `@modern-js/app-tools` in your project. All Modern.js official packages are released with a uniform version number, and version mismatches may cause compatibility issues.
|
|
25
|
+
|
|
26
|
+
Check the version of `@modern-js/app-tools` first, then install the same version of `@modern-js/plugin-bff`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Check the current version of @modern-js/app-tools
|
|
30
|
+
pnpm list @modern-js/app-tools
|
|
31
|
+
|
|
32
|
+
# Install the same version of @modern-js/plugin-bff
|
|
33
|
+
pnpm add @modern-js/plugin-bff@<version>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
:::
|
|
37
|
+
|
|
38
|
+
2. Configure `modern.config.ts`
|
|
39
|
+
|
|
40
|
+
Import and add the BFF plugin in the `modern.config.ts` file:
|
|
41
|
+
|
|
42
|
+
```ts title="modern.config.ts"
|
|
43
|
+
import { defineConfig, appTools } from '@modern-js/app-tools';
|
|
44
|
+
import { bffPlugin } from '@modern-js/plugin-bff';
|
|
45
|
+
|
|
46
|
+
export default defineConfig({
|
|
47
|
+
plugins: [appTools(), bffPlugin()],
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. Configure TypeScript alias
|
|
52
|
+
|
|
53
|
+
To correctly recognize the `@api` alias in TypeScript, it is recommended to add path mapping in `tsconfig.json`:
|
|
54
|
+
|
|
55
|
+
```json title="tsconfig.json"
|
|
56
|
+
{
|
|
57
|
+
"compilerOptions": {
|
|
58
|
+
"paths": {
|
|
59
|
+
..., // other paths,
|
|
60
|
+
"@api/*": ["./api/lambda/*"]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"include": [
|
|
64
|
+
..., // other include directories
|
|
65
|
+
"api" // Add api directory
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
16
69
|
|
|
17
70
|
## BFF Functions
|
|
18
71
|
|
|
@@ -49,7 +102,7 @@ After running `pnpm run dev`, open `http://localhost:8080/` and you can see that
|
|
|
49
102
|
In Modern.js, the routing system for BFF functions is implemented based on the file system, which is another form of **conventional routing**. Each BFF function in the `api/lambda` directory is mapped to an API route. Here are some routing conventions.
|
|
50
103
|
|
|
51
104
|
:::info
|
|
52
|
-
All routes generated by BFF functions have a common prefix, which defaults to `/api`. This can be configured using [bff.prefix](/configure/app/bff/prefix).
|
|
105
|
+
All routes generated by BFF functions have a common prefix, which defaults to `/api`. This can be configured using [bff.prefix](/configure/app/bff/prefix.md).
|
|
53
106
|
:::
|
|
54
107
|
|
|
55
108
|
### Default Routes
|
|
@@ -68,7 +121,7 @@ Nested directories are supported, and files will be automatically parsed into ro
|
|
|
68
121
|
|
|
69
122
|
### Dynamic Routes
|
|
70
123
|
|
|
71
|
-
Similarly, creating a directory or file with `[xxx]` in the name supports dynamic route parameters. The rules for dynamic route function parameters can be found in [dynamic-path](/guides/advanced-features/bff/function#dynamic-path).
|
|
124
|
+
Similarly, creating a directory or file with `[xxx]` in the name supports dynamic route parameters. The rules for dynamic route function parameters can be found in [dynamic-path](/guides/advanced-features/bff/function.md#dynamic-path).
|
|
72
125
|
|
|
73
126
|
- `api/lambda/user/[username]/info.ts` -> `{prefix}/user/:username/info`
|
|
74
127
|
- `api/lambda/user/username/[action].ts` -> `{prefix}/user/username/:action`
|
|
@@ -256,10 +309,10 @@ export default () => {
|
|
|
256
309
|
|
|
257
310
|
## Extend BFF Function
|
|
258
311
|
|
|
259
|
-
|
|
312
|
+
The standard BFF function writing method may not always meet your needs. For example, complex TS type requirements in business scenarios. Modern.js provides a more powerful BFF function writing method.
|
|
260
313
|
|
|
261
|
-
|
|
314
|
+
For more details, please refer to - [Creating Extensible BFF Functions](/guides/advanced-features/bff/operators.md).
|
|
262
315
|
|
|
263
316
|
## Code Sharing
|
|
264
317
|
|
|
265
|
-
Besides the BFF functions in the `api/` directory, which can be referenced in the `src/` directory through an integrated calling method, the `src/` and `api/` directories cannot directly reference each other's code by default. To achieve code sharing, a [`shared`](/
|
|
318
|
+
Besides the BFF functions in the `api/` directory, which can be referenced in the `src/` directory through an integrated calling method, the `src/` and `api/` directories cannot directly reference each other's code by default. To achieve code sharing, a [`shared`](/apis/app/hooks/shared.md) directory can be created at the root of the project for both `src/` and `api/` to use commonly.
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 2
|
|
3
|
-
title: Creating Extensible BFF Functions
|
|
4
|
-
---
|
|
5
|
-
|
|
6
1
|
# Creating Extensible BFF Functions
|
|
7
2
|
|
|
8
3
|
The previous section showed how to export a simple BFF function in a file. In more complex scenarios, each BFF function may need to do independent type validation, pre-logic, etc.
|
|
@@ -31,10 +26,6 @@ A BFF function created by the `Api` function consists of the following parts:
|
|
|
31
26
|
|
|
32
27
|
The server can define the input parameters and types of the interface. Based on the types, the server will automatically perform type validation at runtime:
|
|
33
28
|
|
|
34
|
-
import BFFOperatorCode from '@site-docs/components/bff-operator-code';
|
|
35
|
-
|
|
36
|
-
<BFFOperatorCode>
|
|
37
|
-
|
|
38
29
|
```typescript title="api/lambda/user.ts"
|
|
39
30
|
import { Api, Post, Query, Data } from '@modern-js/plugin-bff/hono-server';
|
|
40
31
|
import { z } from 'zod';
|
|
@@ -59,8 +50,6 @@ export const addUser = Api(
|
|
|
59
50
|
);
|
|
60
51
|
```
|
|
61
52
|
|
|
62
|
-
</BFFOperatorCode>
|
|
63
|
-
|
|
64
53
|
:::caution Note
|
|
65
54
|
When using the `Api` function, ensure that all code logic is placed inside the function. Operations such as `console.log` or using `fs` outside the function are not allowed.
|
|
66
55
|
|
|
@@ -86,8 +75,6 @@ addUser({
|
|
|
86
75
|
|
|
87
76
|
As shown in the example below, you can specify the route and HTTP Method through the `Get` function:
|
|
88
77
|
|
|
89
|
-
<BFFOperatorCode>
|
|
90
|
-
|
|
91
78
|
```typescript title="api/lambda/user.ts"
|
|
92
79
|
import { Api, Get, Query, Data } from '@modern-js/plugin-bff/hono-server';
|
|
93
80
|
|
|
@@ -100,12 +87,8 @@ export const getHello = Api(
|
|
|
100
87
|
);
|
|
101
88
|
```
|
|
102
89
|
|
|
103
|
-
</BFFOperatorCode>
|
|
104
|
-
|
|
105
90
|
When the route is not specified, the interface route is defined according to the file convention. As shown in the example below, with the function writing method, there is a code path `api/lambda/user.ts`, which will register the corresponding interface `/api/user`.
|
|
106
91
|
|
|
107
|
-
<BFFOperatorCode>
|
|
108
|
-
|
|
109
92
|
```typescript title="api/lambda/user.ts"
|
|
110
93
|
import { Api, Get, Query, Data } from '@modern-js/plugin-bff/hono-server';
|
|
111
94
|
|
|
@@ -113,10 +96,8 @@ import { Api, Get, Query, Data } from '@modern-js/plugin-bff/hono-server';
|
|
|
113
96
|
export const get = Api(Query(UserSchema), async ({ query }) => query);
|
|
114
97
|
```
|
|
115
98
|
|
|
116
|
-
</BFFOperatorCode>
|
|
117
|
-
|
|
118
99
|
:::info
|
|
119
|
-
Modern.js recommends defining interfaces based on file conventions to keep routes clear in the project. For specific rules, see [Function Routes](/guides/advanced-features/bff/function#function-routes).
|
|
100
|
+
Modern.js recommends defining interfaces based on file conventions to keep routes clear in the project. For specific rules, see [Function Routes](/guides/advanced-features/bff/function.md#function-routes).
|
|
120
101
|
|
|
121
102
|
:::
|
|
122
103
|
|
|
@@ -140,8 +121,6 @@ The following are request-related operators. Operators can be combined, but must
|
|
|
140
121
|
|
|
141
122
|
Using the `Query` function, you can define the type of query. After using the `Query` function, the query information can be obtained in the input parameters of the interface processing function, and the `query` field can be added to the input parameters of the frontend request function:
|
|
142
123
|
|
|
143
|
-
<BFFOperatorCode>
|
|
144
|
-
|
|
145
124
|
```typescript title="api/lambda/user.ts"
|
|
146
125
|
// Server-side code
|
|
147
126
|
import { Api, Query } from '@modern-js/plugin-bff/hono-server';
|
|
@@ -157,8 +136,6 @@ export const get = Api(Query(UserSchema), async ({ query }) => ({
|
|
|
157
136
|
}));
|
|
158
137
|
```
|
|
159
138
|
|
|
160
|
-
</BFFOperatorCode>
|
|
161
|
-
|
|
162
139
|
```typescript title="routes/page.tsx"
|
|
163
140
|
// Frontend code
|
|
164
141
|
get({
|
|
@@ -173,8 +150,6 @@ get({
|
|
|
173
150
|
|
|
174
151
|
URL query parameters are strings by default. If you need numeric types, you need to use `z.coerce.number()` for type conversion:
|
|
175
152
|
|
|
176
|
-
<BFFOperatorCode>
|
|
177
|
-
|
|
178
153
|
```typescript title="api/lambda/user.ts"
|
|
179
154
|
import { Api, Get, Query } from '@modern-js/plugin-bff/hono-server';
|
|
180
155
|
import { z } from 'zod';
|
|
@@ -198,8 +173,6 @@ export const getUser = Api(
|
|
|
198
173
|
);
|
|
199
174
|
```
|
|
200
175
|
|
|
201
|
-
</BFFOperatorCode>
|
|
202
|
-
|
|
203
176
|
:::caution Note
|
|
204
177
|
URL query parameters are all string types. If you need numeric types, you need to use `z.coerce.number()` for conversion, not `z.number()` directly.
|
|
205
178
|
:::
|
|
@@ -213,8 +186,6 @@ If you use the Data function, you must follow the HTTP protocol. When the HTTP M
|
|
|
213
186
|
|
|
214
187
|
:::
|
|
215
188
|
|
|
216
|
-
<BFFOperatorCode>
|
|
217
|
-
|
|
218
189
|
```typescript title="api/lambda/user.ts"
|
|
219
190
|
import { Api, Data } from '@modern-js/plugin-bff/hono-server';
|
|
220
191
|
import { z } from 'zod';
|
|
@@ -230,8 +201,6 @@ export const post = Api(Data(DataSchema), async ({ data }) => ({
|
|
|
230
201
|
}));
|
|
231
202
|
```
|
|
232
203
|
|
|
233
|
-
</BFFOperatorCode>
|
|
234
|
-
|
|
235
204
|
```typescript title="routes/page.tsx"
|
|
236
205
|
// Frontend code
|
|
237
206
|
post({
|
|
@@ -246,8 +215,6 @@ post({
|
|
|
246
215
|
|
|
247
216
|
Route parameters can implement dynamic routes and get parameters from the path. You can specify path parameters through `Params<T>(schema: z.ZodType<T>)`
|
|
248
217
|
|
|
249
|
-
<BFFOperatorCode>
|
|
250
|
-
|
|
251
218
|
```typescript
|
|
252
219
|
import { Api, Get, Params } from '@modern-js/plugin-bff/hono-server';
|
|
253
220
|
import { z } from 'zod';
|
|
@@ -265,14 +232,10 @@ export const queryUser = Api(
|
|
|
265
232
|
);
|
|
266
233
|
```
|
|
267
234
|
|
|
268
|
-
</BFFOperatorCode>
|
|
269
|
-
|
|
270
235
|
### Request Headers
|
|
271
236
|
|
|
272
237
|
You can define the request headers required by the interface through the `Headers<T>(schema: z.ZodType<T>)` function and pass the request headers through integrated calls:
|
|
273
238
|
|
|
274
|
-
<BFFOperatorCode>
|
|
275
|
-
|
|
276
239
|
```typescript
|
|
277
240
|
import { Api, Headers } from '@modern-js/plugin-bff/hono-server';
|
|
278
241
|
import { z } from 'zod';
|
|
@@ -286,8 +249,6 @@ export const queryUser = Api(Headers(headerSchema), async ({ headers }) => ({
|
|
|
286
249
|
}));
|
|
287
250
|
```
|
|
288
251
|
|
|
289
|
-
</BFFOperatorCode>
|
|
290
|
-
|
|
291
252
|
## Parameter Validation
|
|
292
253
|
|
|
293
254
|
As mentioned earlier, when using functions such as `Query` and `Data` to define interfaces, the server will automatically validate the data passed from the frontend based on the schema passed to these functions.
|
|
@@ -333,8 +294,6 @@ The `Middleware` operator can be configured multiple times, and the execution or
|
|
|
333
294
|
|
|
334
295
|
:::
|
|
335
296
|
|
|
336
|
-
<BFFOperatorCode>
|
|
337
|
-
|
|
338
297
|
```typescript
|
|
339
298
|
import { Api, Query, Middleware } from '@modern-js/plugin-bff/hono-server';
|
|
340
299
|
import { z } from 'zod';
|
|
@@ -356,8 +315,6 @@ export const get = Api(
|
|
|
356
315
|
);
|
|
357
316
|
```
|
|
358
317
|
|
|
359
|
-
</BFFOperatorCode>
|
|
360
|
-
|
|
361
318
|
## Data Transformation Pipe
|
|
362
319
|
|
|
363
320
|
The `Pipe` operator can pass in a function that executes after middleware and validation are completed. It can be used in the following scenarios:
|
|
@@ -373,8 +330,6 @@ The `Pipe` operator can be configured multiple times. The execution order of fun
|
|
|
373
330
|
|
|
374
331
|
:::
|
|
375
332
|
|
|
376
|
-
<BFFOperatorCode>
|
|
377
|
-
|
|
378
333
|
```typescript
|
|
379
334
|
import { Api, Query, Pipe } from '@modern-js/plugin-bff/hono-server';
|
|
380
335
|
import { z } from 'zod';
|
|
@@ -401,12 +356,8 @@ export const get = Api(
|
|
|
401
356
|
);
|
|
402
357
|
```
|
|
403
358
|
|
|
404
|
-
</BFFOperatorCode>
|
|
405
|
-
|
|
406
359
|
Also,
|
|
407
360
|
|
|
408
|
-
<BFFOperatorCode>
|
|
409
|
-
|
|
410
361
|
```typescript
|
|
411
362
|
import { Api, Query, Pipe } from '@modern-js/plugin-bff/hono-server';
|
|
412
363
|
import { z } from 'zod';
|
|
@@ -436,12 +387,8 @@ export const get = Api(
|
|
|
436
387
|
);
|
|
437
388
|
```
|
|
438
389
|
|
|
439
|
-
</BFFOperatorCode>
|
|
440
|
-
|
|
441
390
|
If you need to do more custom operations on the response, you can pass a function to the `end` function. The input parameter of the function is Hono's Context (`c`), and you can operate on `c.req` and `c.res`:
|
|
442
391
|
|
|
443
|
-
<BFFOperatorCode>
|
|
444
|
-
|
|
445
392
|
```typescript
|
|
446
393
|
import { Api, Query, Pipe } from '@modern-js/plugin-bff/hono-server';
|
|
447
394
|
import { z } from 'zod';
|
|
@@ -474,8 +421,6 @@ export const get = Api(
|
|
|
474
421
|
);
|
|
475
422
|
```
|
|
476
423
|
|
|
477
|
-
</BFFOperatorCode>
|
|
478
|
-
|
|
479
424
|
## Response
|
|
480
425
|
|
|
481
426
|
The following are response-related operators. Through response operators, you can process responses.
|
|
@@ -484,8 +429,6 @@ The following are response-related operators. Through response operators, you ca
|
|
|
484
429
|
|
|
485
430
|
You can specify the status code returned by the interface through the `HttpCode(statusCode: number)` function
|
|
486
431
|
|
|
487
|
-
<BFFOperatorCode>
|
|
488
|
-
|
|
489
432
|
```typescript
|
|
490
433
|
import { Api, Query, Data, HttpCode } from '@modern-js/plugin-bff/hono-server';
|
|
491
434
|
import { z } from 'zod';
|
|
@@ -514,14 +457,10 @@ export const post = Api(
|
|
|
514
457
|
);
|
|
515
458
|
```
|
|
516
459
|
|
|
517
|
-
</BFFOperatorCode>
|
|
518
|
-
|
|
519
460
|
### Response Headers SetHeaders
|
|
520
461
|
|
|
521
462
|
Supports setting response headers through the `SetHeaders(headers: Record<string, string>)` function
|
|
522
463
|
|
|
523
|
-
<BFFOperatorCode>
|
|
524
|
-
|
|
525
464
|
```typescript
|
|
526
465
|
import { Api, Get, SetHeaders } from '@modern-js/plugin-bff/hono-server';
|
|
527
466
|
|
|
@@ -534,14 +473,10 @@ export default Api(
|
|
|
534
473
|
);
|
|
535
474
|
```
|
|
536
475
|
|
|
537
|
-
</BFFOperatorCode>
|
|
538
|
-
|
|
539
476
|
### Redirect
|
|
540
477
|
|
|
541
478
|
Supports redirecting the interface through `Redirect(url: string)`:
|
|
542
479
|
|
|
543
|
-
<BFFOperatorCode>
|
|
544
|
-
|
|
545
480
|
```typescript
|
|
546
481
|
import { Api, Get, Redirect } from '@modern-js/plugin-bff/hono-server';
|
|
547
482
|
|
|
@@ -552,13 +487,9 @@ export default Api(
|
|
|
552
487
|
);
|
|
553
488
|
```
|
|
554
489
|
|
|
555
|
-
</BFFOperatorCode>
|
|
556
|
-
|
|
557
490
|
## Request Context
|
|
558
491
|
|
|
559
|
-
As mentioned above, through operators, you can get `query`, `data`, `params`, etc. in the input parameters of the interface processing function. But sometimes we need to get more request context information. At this time, we can get it through [`useHonoContext`](/apis/app/runtime/bff/use-backend-context):
|
|
560
|
-
|
|
561
|
-
<BFFOperatorCode>
|
|
492
|
+
As mentioned above, through operators, you can get `query`, `data`, `params`, etc. in the input parameters of the interface processing function. But sometimes we need to get more request context information. At this time, we can get it through [`useHonoContext`](/apis/app/runtime/bff/use-backend-context.md):
|
|
562
493
|
|
|
563
494
|
```typescript title="api/lambda/user.ts"
|
|
564
495
|
import { Api, Get, Query } from '@modern-js/plugin-bff/hono-server';
|
|
@@ -584,8 +515,6 @@ export const queryUser = Api(
|
|
|
584
515
|
);
|
|
585
516
|
```
|
|
586
517
|
|
|
587
|
-
</BFFOperatorCode>
|
|
588
|
-
|
|
589
518
|
## FAQ
|
|
590
519
|
|
|
591
520
|
### Can I use TypeScript instead of zod schema
|
|
@@ -607,8 +536,6 @@ For specific comparisons of different solutions, you can refer to [Why Use Zod](
|
|
|
607
536
|
|
|
608
537
|
In frontend development, some server interfaces (such as some configuration interfaces) have long response times, but actually don't need to be updated for a long time. For such interfaces, we can set HTTP cache to improve page performance:
|
|
609
538
|
|
|
610
|
-
<BFFOperatorCode>
|
|
611
|
-
|
|
612
539
|
```typescript
|
|
613
540
|
import { Api, SetHeaders } from '@modern-js/plugin-bff/hono-server';
|
|
614
541
|
|
|
@@ -625,5 +552,3 @@ export const get = Api(
|
|
|
625
552
|
},
|
|
626
553
|
);
|
|
627
554
|
```
|
|
628
|
-
|
|
629
|
-
</BFFOperatorCode>
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: BFF
|
|
3
|
-
---
|
|
4
|
-
|
|
5
1
|
# BFF
|
|
6
2
|
|
|
7
3
|
BFF (Backends for Frontends) is an architectural pattern primarily used to address issues of data aggregation in front-end and back-end collaboration. Under the BFF architecture, front-end applications do not communicate directly with backend services. Instead, they interact with backend services through a dedicated BFF middleware layer, custom-made for the front end.
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 12
|
|
3
|
-
---
|
|
4
|
-
|
|
5
1
|
# Improve Build Performance
|
|
6
2
|
|
|
7
3
|
Modern.js optimizes build performance by default, but as the project becomes larger, you may encounter some build performance problems.
|
|
@@ -9,7 +5,7 @@ Modern.js optimizes build performance by default, but as the project becomes lar
|
|
|
9
5
|
This document provides some optional speed-up strategies, developers can choose some of them to improve the build performance.
|
|
10
6
|
|
|
11
7
|
:::tip 📢 Notice
|
|
12
|
-
The strategies in [Bundle Size Optimization](/guides/advanced-features/page-performance/optimize-bundle) can also be used to improve build performance, so we won't repeat them here.
|
|
8
|
+
The strategies in [Bundle Size Optimization](/guides/advanced-features/page-performance/optimize-bundle.md) can also be used to improve build performance, so we won't repeat them here.
|
|
13
9
|
:::
|
|
14
10
|
|
|
15
11
|
## General optimization strategy
|
|
@@ -96,7 +92,7 @@ export default {
|
|
|
96
92
|
|
|
97
93
|
### Adjust Browserslist for development
|
|
98
94
|
|
|
99
|
-
This strategy is similar to ["Adjust Browserslist"](/guides/advanced-features/page-performance/optimize-bundle#adjust-browserslist), the difference is that we can set different browserslist for development and production environment, thereby reducing the compilation overhead in the development environment.
|
|
95
|
+
This strategy is similar to ["Adjust Browserslist"](/guides/advanced-features/page-performance/optimize-bundle.md#adjust-browserslist), the difference is that we can set different browserslist for development and production environment, thereby reducing the compilation overhead in the development environment.
|
|
100
96
|
|
|
101
97
|
For example, you can add the following config to `package.json`, which means that only the latest browsers are compatible in the development environment, and the actual browsers are compatible in the production environment:
|
|
102
98
|
|
|
@@ -131,4 +127,4 @@ export default {
|
|
|
131
127
|
};
|
|
132
128
|
```
|
|
133
129
|
|
|
134
|
-
See [output.sourceMap](/
|
|
130
|
+
See [output.sourceMap](/configure/app/output/source-map.md) for details.
|