Skip to content

[APPS] Add vite dev server middleware for local backend function testing#285

Draft
sdkennedy2 wants to merge 1 commit intosdkennedy2/apps-backend-functions-uploadfrom
sdkennedy2/apps-dev-server-middleware
Draft

[APPS] Add vite dev server middleware for local backend function testing#285
sdkennedy2 wants to merge 1 commit intosdkennedy2/apps-backend-functions-uploadfrom
sdkennedy2/apps-dev-server-middleware

Conversation

@sdkennedy2
Copy link
Collaborator

@sdkennedy2 sdkennedy2 commented Mar 10, 2026

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 Datadog single_action_runs API, 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.ts approach (reusing shared constants from backend-shared.ts) but adds dev-specific behavior:

  • Reads files at request time for instant feedback on code changes
  • Detects default exports and re-exports them as named exports for the script wrapper
  • Includes a lodash import preamble matching the Action Platform runtime environment

The middleware is registered via unplugin's vite.configureServer hook and only activates during Vite dev server usage — no impact on production builds or other bundlers.

QA Instructions

  1. Set up a high code app with a backend/ directory containing a function module
  2. Configure valid DD_API_KEY, DD_APP_KEY, and DD_SITE environment variables
  3. Run vite dev with the Datadog plugin configured
  4. Send a POST request to http://localhost:<port>/__dd/executeAction with { "functionName": "myFunc", "args": [1, 2] }
  5. Verify the function executes and returns a result
  6. Test /__dd/debugBundle with { "functionName": "myFunc" } to inspect the bundled output

Blast Radius

  • Only active during Vite dev server mode — zero impact on production builds
  • Only affects apps using the Datadog vite plugin with valid auth credentials
  • Adds vite as a dependency to the apps plugin package

Documentation

Copy link
Collaborator Author

sdkennedy2 commented Mar 10, 2026

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sdkennedy2 sdkennedy2 marked this pull request as draft March 10, 2026 17:55
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/apps-dev-server-middleware branch from 7168034 to e6fa6c7 Compare March 10, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant