[APPS] Support importing .backend.ts files as RPC proxies from frontend code#306
Draft
sdkennedy2 wants to merge 1 commit intosdkennedy2/apps-vite-dev-serverfrom
Draft
[APPS] Support importing .backend.ts files as RPC proxies from frontend code#306sdkennedy2 wants to merge 1 commit intosdkennedy2/apps-vite-dev-serverfrom
sdkennedy2 wants to merge 1 commit intosdkennedy2/apps-vite-dev-serverfrom
Conversation
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
Currently, backend functions must live in a dedicated
backend/directory to be discovered and bundled. This means frontend code has no ergonomic way to import a backend function directly — developers have to know the function name as a string and wire up theexecuteBackendFunctioncall manually.This PR adds support for co-locating backend functions alongside frontend code using a
*.backend.tsnaming convention. When frontend code imports a.backend.tsfile, the build system automatically intercepts the import and serves a lightweight RPC proxy instead of the real server-side source.Changes
Introduced a Vite plugin (
backend-proxy-plugin.ts) that hooks intoresolveIdandloadto intercept*.backend.tsimports in frontend code. When such an import is detected:\0dd-backend-proxy:)executeBackendFunctionfrom@datadog/apps-function-queryThe generated proxy module looks like:
Key architectural decisions:
proxy-codegen.ts): Separated into its own module for testability. Generates a thin wrapper that routes through the existingexecuteBackendFunctiontransport layer (dev-server HTTP or iframe postMessage).*.backend.tsimports are merged with directory-discovered functions at bothcloseBundle(production) andconfigureServer(dev) time. Deduplication is by function name.createDevServerMiddlewarenow accepts a() => BackendFunction[]getter so that lazily-discovered functions are visible without restarting the dev server.hasBackendmoved to upload time: ThehasBackendflag now checksbackendOutputs.sizeinstead of the initial discovery count, ensuring import-discovered functions are included in the backend/frontend asset split.QA Instructions
*.backend.tsfile outside thebackend/directory (e.g.src/getGreeting.backend.ts)Blast Radius
packages/plugins/apps/src/vite/)*.backend.(ts|tsx|js|jsx)pattern — no impact on regular importsDocumentation