[APPS] Add vite dev server middleware for local backend function testing#285
Draft
sdkennedy2 wants to merge 1 commit intosdkennedy2/apps-backend-functions-uploadfrom
Draft
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. |
7168034 to
e6fa6c7
Compare
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
Developing backend functions requires a fast local feedback loop. Without a dev server, developers would need to upload and deploy to test every change. This middleware enables local execution of backend functions against the Datadog Action Platform API directly from the Vite dev server.
Changes
Added Vite dev server middleware that registers two POST endpoints:
/__dd/executeAction— bundles a backend function on-the-fly with esbuild, transforms it into the Action Platform script format, executes it via the Datadogsingle_action_runsAPI, and polls for the result. Accepts{ functionName, args? }in the request body./__dd/debugBundle— returns the raw bundled code for a backend function, useful for inspecting what gets sent to the Action Platform.The bundling pipeline mirrors the production
backend-functions.tsapproach (reusing shared constants frombackend-shared.ts) but adds dev-specific behavior:The middleware is registered via unplugin's
vite.configureServerhook and only activates during Vite dev server usage — no impact on production builds or other bundlers.QA Instructions
backend/directory containing a function moduleDD_API_KEY,DD_APP_KEY, andDD_SITEenvironment variablesvite devwith the Datadog plugin configuredhttp://localhost:<port>/__dd/executeActionwith{ "functionName": "myFunc", "args": [1, 2] }/__dd/debugBundlewith{ "functionName": "myFunc" }to inspect the bundled outputBlast Radius
viteas a dependency to the apps plugin packageDocumentation