Skip to content

Add Vercel serverless deployment support for Express app#3

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/add-vercel-deployment-support
Draft

Add Vercel serverless deployment support for Express app#3
Copilot wants to merge 3 commits into
mainfrom
copilot/add-vercel-deployment-support

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 4, 2025

Vercel deployments currently return 404 because the Express/EJS app lacks a serverless adapter and proper routing configuration.

Changes

  • api/index.js: Serverless wrapper that attempts to load Express app from common entry points (../app, ../server, ../src/app, ../src/server, ./app), wraps with serverless-http, and returns actionable error JSON if app not found
  • vercel.json: Routes all requests to serverless function with Node 18 runtime
  • package.json: Add serverless-http@^3.0.0 dependency
  • PROPOSED_CHANGE.md: Maintainer instructions for required code changes

Required Follow-up

Current app.js calls app.listen() directly without exporting the Express instance. Maintainers must add:

// At end of app.js
module.exports = app;

Alternatively, use conditional export:

mongoose
  .connect(dbURI)
  .then((result) => {
    if (require.main === module) {
      app.listen(3000);
    }
  })
  .catch((err) => console.error(err));

module.exports = app;

See PROPOSED_CHANGE.md for complete guidance on MongoDB connection strings and environment variables.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • nodeproject.62tovra.mongodb.net
    • Triggering command: node -e // Test that api/index.js can be required const handler = require('./api/index.js'); console.log('✓ api/index.js can be required successfully'); console.log('Handler type:', typeof handler); (dns block)
    • Triggering command: node -e const app = require('./app.js'); console.log('App loaded:', typeof app); console.log('Is function:', typeof app === 'function'); console.log('Has _router:', app && app._router !== undefined); (dns block)
    • Triggering command: node -e const handler = require('./api/index.js'); const mockReq = {}; const mockRes = { status: function(code) { this.statusCode = code; return this; }, json: function(data) { console.log('Status:', this.statusCode); console.log('Response:', JSON.stringify(data, null, 2)); } }; handler(mockReq, mockRes); (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Issue: Vercel deployment returns 404 (screenshot attached). Vercel likely can't find a build output or a compatible server entrypoint for an Express/EJS app.

Goal: Create a PR that makes this repository deployable on Vercel by adding a serverless adapter for an Express app, an explicit vercel.json to route requests to the function, and add serverless-http to dependencies.

Files to add:

  • api/index.js: serverless wrapper that attempts to require the Express app from common entrypoints (../app, ../server, ../src/app, ../src/server, ./app) and wraps it with serverless-http. If no app is found, it returns a helpful JSON error message.
  • vercel.json: declare the Node 18 runtime for the function and rewrite all routes to /api/index.js so client-side routing won't 404.
  • PROPOSED_CHANGE.md: a short explanation and instructions for maintainers.

File to modify:

  • package.json: add dependency "serverless-http": "^3.0.0" under dependencies, preserving the rest of package.json content.

Notes for maintainers:

  • If the project's server file currently calls app.listen() directly, update it to export the Express app instance (examples included in PROPOSED_CHANGE.md). A local server.js can call listen for development.
  • If the project is actually a Next.js or static SPA app, a different approach is necessary; this PR targets an Express/EJS app.

Attached screenshot: image1

Please add these files and the package.json change on a new branch and open a PR against main. After merge, Vercel should install dependencies and redeploy. If any file paths differ in the repo, maintainers should update api/index.js to require the correct entrypoint. The PR should not overwrite existing files other than updating package.json to include the added dependency.

This pull request was created as a result of the following prompt from Copilot chat.

Issue: Vercel deployment returns 404 (screenshot attached). Vercel likely can't find a build output or a compatible server entrypoint for an Express/EJS app.

Goal: Create a PR that makes this repository deployable on Vercel by adding a serverless adapter for an Express app, an explicit vercel.json to route requests to the function, and add serverless-http to dependencies.

Files to add:

  • api/index.js: serverless wrapper that attempts to require the Express app from common entrypoints (../app, ../server, ../src/app, ../src/server, ./app) and wraps it with serverless-http. If no app is found, it returns a helpful JSON error message.
  • vercel.json: declare the Node 18 runtime for the function and rewrite all routes to /api/index.js so client-side routing won't 404.
  • PROPOSED_CHANGE.md: a short explanation and instructions for maintainers.

File to modify:

  • package.json: add dependency "serverless-http": "^3.0.0" under dependencies, preserving the rest of package.json content.

Notes for maintainers:

  • If the project's server file currently calls app.listen() directly, update it to export the Express app instance (examples included in PROPOSED_CHANGE.md). A local server.js can call listen for development.
  • If the project is actually a Next.js or static SPA app, a different approach is necessary; this PR targets an Express/EJS app.

Attached screenshot: image1

Please add these files and the package.json change on a new branch and open a PR against main. After merge, Vercel should install dependencies and redeploy. If any file paths differ in the repo, maintainers should update api/index.js to require the correct entrypoint. The PR should not overwrite existing files other than updating package.json to include the added dependency.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 4, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
blog-node Ready Ready Preview Comment Nov 4, 2025 6:47pm

Co-authored-by: Faizal-Malek <94194196+Faizal-Malek@users.noreply.github.com>
Co-authored-by: Faizal-Malek <94194196+Faizal-Malek@users.noreply.github.com>
Copilot AI changed the title [WIP] Add serverless adapter for Vercel deployment Add Vercel serverless deployment support for Express app Nov 4, 2025
Copilot AI requested a review from Faizal-Malek November 4, 2025 18:51
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.

2 participants