Skip to content

Replace bridge.js child-process adapter with direct NextServer wrapper #7

@aynaash

Description

@aynaash

Summary

The current Lambda handler (bridge.js) spawns node server.js as a child process, waits for it to start (polling 50×100ms), then proxies HTTP requests. This adds ~2-5 seconds of cold start latency.

Current Architecture

Lambda invocation
  → bridge.js handler
    → spawn("node", ["server.js"])  // ~1-3s to start
    → poll 127.0.0.1:3000 (50 retries × 100ms)  // ~2-5s
    → proxy request via http.request()
    → return response

Target Architecture (OpenNext-style)

Lambda invocation
  → index.mjs handler
    → import NextServer from ".next/standalone/server.js"
    → convert Lambda event to Node.js request
    → NextServer.handle(req, res)
    → convert response to Lambda format
    → return response

Benefits

  • Cold start: ~5-10s → ~1.3s (eliminates subprocess + polling)
  • Simpler code — no HTTP proxying between processes
  • Better error handling — stack traces from Next.js are visible
  • Memory efficiency — one Node.js process instead of two

Files to Modify

  • internal/packaging/serverless_packager.go — Replace bridge.js content with NextServer adapter
  • cli/internal/serverless/aws.go — Remove duplicate bridge.js (line 28)
  • cli/internal/serverless/aws_lambda.go — Update handler path to index.handler

References

Difficulty: Hard · Language: Go + JavaScript

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions