Skip to content

Add Vercel serverless deployment support with serverless-http adapter#2

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/add-serverless-adapter-configuration
Draft

Add Vercel serverless deployment support with serverless-http adapter#2
Copilot wants to merge 4 commits into
mainfrom
copilot/add-serverless-adapter-configuration

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 4, 2025

Vercel deployment was returning 404 due to missing serverless configuration. This PR enables the Express/EJS app to run as a Vercel serverless function.

Changes

New files:

  • api/index.js - Serverless wrapper using serverless-http that attempts to load app from common paths (../app, ../server, etc.)
  • vercel.json - Node 18 runtime config with route rewrites to /api/index.js
  • PROPOSED_CHANGE.md - Deployment guide and security notes
  • .gitignore - Excludes node_modules, .env, logs

Modified files:

  • app.js - Now exports the app instance with conditional listen() for local dev:
    mongoose.connect(dbURI).then(() => {
      if (require.main === module) {
        app.listen(3000);
      }
    });
    module.exports = app;
  • package.json - Added serverless-http@^3.0.0, fixed start script to use app.js

Security Note

⚠️ MongoDB credentials are currently hardcoded in app.js. Move to environment variables before deployment:

  1. Set MONGODB_URI in Vercel dashboard
  2. Update app.js: const dbURI = process.env.MONGODB_URI

See PROPOSED_CHANGE.md for detailed deployment steps.

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 try { const app = require('./app'); console.log('App loaded successfully:', typeof app); } catch(e) { console.error('Error loading app:', e.message); } (dns block)
    • Triggering command: node -e const app = require('./app'); console.log('✓ App exports successfully'); console.log('✓ App type:', typeof app); console.log('✓ Has listen method:', typeof app.listen); (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 returned 404 (screenshot attached). Vercel likely can't find a build output or a compatible server entrypoint. Goal: Add a serverless adapter and configuration so the Express/EJS app can run on Vercel as a serverless function, and add serverless-http as a dependency.

What this PR will do:

  • Add api/index.js: a serverless wrapper that attempts to require existing Express app from common locations (../app, ../server, ../src/app, ../src/server) and wraps it with serverless-http. If not found, it returns a helpful JSON error message.
  • Add vercel.json: declare Node 18 runtime for the function and rewrite all routes to /api/index.js so client-side routing doesn't 404.
  • Add PROPOSED_CHANGE.md: short explanation and instructions for maintainers.
  • Update package.json to add "serverless-http": "^3.0.0" to dependencies (preserving existing content). Also ensure scripts include build/start if appropriate (no destructive changes).

Files to add or modify:

  • api/index.js (new)
  • vercel.json (new)
  • PROPOSED_CHANGE.md (new)
  • package.json (modified to include dependency)

Notes for maintainers:

  • If your Express app currently calls app.listen() in its module, change it to export the app instance (example provided in PROPOSED_CHANGE.md).
  • If your project is actually a Next.js or static SPA app, let me know and I can adjust the approach.

Attached screenshot: image1

Please merge the PR and redeploy on Vercel. After merge, run npm install or redeploy via Vercel (it will install dependencies).

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

Issue: Vercel deployment returned 404 (screenshot attached). Vercel likely can't find a build output or a compatible server entrypoint. Goal: Add a serverless adapter and configuration so the Express/EJS app can run on Vercel as a serverless function, and add serverless-http as a dependency.

What this PR will do:

  • Add api/index.js: a serverless wrapper that attempts to require existing Express app from common locations (../app, ../server, ../src/app, ../src/server) and wraps it with serverless-http. If not found, it returns a helpful JSON error message.
  • Add vercel.json: declare Node 18 runtime for the function and rewrite all routes to /api/index.js so client-side routing doesn't 404.
  • Add PROPOSED_CHANGE.md: short explanation and instructions for maintainers.
  • Update package.json to add "serverless-http": "^3.0.0" to dependencies (preserving existing content). Also ensure scripts include build/start if appropriate (no destructive changes).

Files to add or modify:

  • api/index.js (new)
  • vercel.json (new)
  • PROPOSED_CHANGE.md (new)
  • package.json (modified to include dependency)

Notes for maintainers:

  • If your Express app currently calls app.listen() in its module, change it to export the app instance (example provided in PROPOSED_CHANGE.md).
  • If your project is actually a Next.js or static SPA app, let me know and I can adjust the approach.

Attached screenshot: image1

Please merge the PR and redeploy on Vercel. After merge, run npm install or redeploy via Vercel (it will install dependencies).


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

@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 3:36pm

Co-authored-by: Faizal-Malek <94194196+Faizal-Malek@users.noreply.github.com>
…script

Co-authored-by: Faizal-Malek <94194196+Faizal-Malek@users.noreply.github.com>
…ty warnings

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