Skip to content

A reverse-proxy API middleware for Vercel Serverless

Notifications You must be signed in to change notification settings

aefji/reverse-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Reverse-proxy API middleware

A small reverse proxy API middleware for Vercel Serverless Functions lands. Often used in combination with Vercel frontend apps.

Usage

  1. Add the destination API URLs and/or Tokens as Environment Variables in the Vercel dashboard during build. API_TOKEN, API_URL etc.
  2. Create one .js file for every proxy API endpoint you would like to add. i.e. for /api/path create an /api/path.js file
  3. Add any additional headers in the proxy.js file
  4. Add the following to path.js
/**
* Module dependencies
*/
const express = require("express");
const proxy = require("./proxy");

/**
* Expose the app
*/
const app = (module.exports = express());

/**
* Mount the proxy middleware
*/
app.use("/api/path", proxy(process.env.API_URL));
  1. Make the request to https://your-vercel-domain/api/path to reach the https://destination-API-endpoint/

Credits

Inspired by simple-http-proxy.

Releases

No releases published

Packages

No packages published