Migrate server backend from Express to Next.js#78
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
Migrate server backend from Express to Next.js#78devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Nader Dabit <dabit3@gmail.com>
dabit3
self-requested a review
July 17, 2026 17:28
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Nader Dabit <dabit3@gmail.com>
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.
Summary
Rewrites the
server/backend from a standalone Express app to a Next.js 16 (App Router) app. All endpoints keep the exact same URL paths and payloads, so the Expo client (app/) and the CLI need no changes — the mobile app still points atDOMAINand hits/chat/:provider,/images/:provider,/models,/health.Endpoint mapping (paths unchanged, no
/apiprefix)GET /health→app/health/route.tsGET /models→app/models/route.tsPOST /chat/[provider]→app/chat/[provider]/route.ts(claude, gpt, gemini, glm, kimi; SSE streaming)POST /images/[provider]→app/images/[provider]/route.ts(gemini; multipart and JSON)What changed structurally
server/src/**to framework-agnostic functions inserver/lib/**:ChatRequestand return a streamingResponseinstead of writing to an Expressres. Dispatch is aCHAT_HANDLERSmap inlib/chat/index.ts(replaceschatRouter).{ model, prompt, file }and returns a JSONResponse(replaces multer — the route parsesmultipart/form-dataviareq.formData()).lib/sse.tsrewritten around Web Streams:createSSEParser/pumpStream(partial-line buffering across chunks) are preserved.lib/auth.ts— optionalAuthorization: Bearer <API_AUTH_TOKEN>check (timing-safe), returns401Responseornull.lib/rateLimit.ts— in-memory fixed-window limiter keyed by client IP (RATE_LIMIT_PER_MINUTE, default 60), returns429withRetry-After/RateLimit-*headers.proxy.ts(Next 16's renamedmiddleware) — CORS headers +OPTIONSpreflight for the matched routes (CORS_ORIGIN, default*).lib/types.ts) and the model registry (lib/models.ts) are carried over unchanged;/modelsstill omits internalmodelId.Tooling / behavior
package.jsonswapsexpress/cors/multer/express-rate-limit/supertestfornext/react/react-dom(pinnednext@16.2.10,react@19.2.3to match the app).zodkept.dev/startrun on port 3050 (next dev/start -p 3050) so the bundledngrokflow and the CLI'sEXPO_PUBLIC_DEV_API_URL=http://localhost:3050keep working.typecheck(tsc --noEmit) andtest(vitest) preserved — CI's server job is unchanged.401, invalid-body400, unsupported-model and provider-error events.Verification
pnpm install --frozen-lockfile,pnpm typecheck,pnpm test(9 passing), andpnpm buildall green.next startand manually confirmed:/health,/models(nomodelIdleak), CORS preflight204, SSE unsupported-model + provider-error passthrough (real upstream401/403without keys), invalid-body400, unknown-provider404, and multipart image parsing.Link to Devin session: https://app.devin.ai/sessions/d96e95fc4d5948e0b34d96635f14fb69
Requested by: @dabit3