MCPcopy Index your code
hub / github.com/dougmoscrop/serverless-http

github.com/dougmoscrop/serverless-http @v4.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.0.0 ↗ · + Follow
43 symbols 95 edges 56 files 0 documented · 0% 20 cross-repo links updated 10mo ago★ 1,77852 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

serverless-http

Description

This module allows you to 'wrap' your API for serverless use. No HTTP server, no ports or sockets. Just your code in the same execution pipeline you are already familiar with.

Sponsors

Thank you to Upstash for reaching out to sponsor this project!

Upstash

Upstash: Serverless Database for Redis

  • Serverless Redis with global replication and durable storage
  • Price scales to zero with per request pricing
  • Built-in REST API designed for serverless and edge functions
[Start for free in 30 seconds!](https://upstash.com/?utm_source=serverless-http)

Support

Supported Frameworks

(* Experimental)

  • Node (http.createServer)
  • Connect
  • Express
  • Koa
  • Restana
  • Sails *
  • Hapi *
  • Fastify *
  • Restify *
  • Polka *
  • Loopback *

Supported Providers

  • AWS
  • Genezio
  • Azure (Experimental, untested, probably outdated)

Deploy a Hello Word on Genezio

:rocket: You can deploy your own hello world example using the Express framework to Genezio with one click:

Deploy to Genezio

Examples

Please check the examples folder!

Usage example using the Koa framework

const serverless = require('serverless-http');
const Koa = require('koa'); // or any supported framework

const app = new Koa();

app.use(/* register your middleware as normal */);

// this is it!
module.exports.handler = serverless(app);

// or as a promise
const handler = serverless(app);
module.exports.handler = async (event, context) => {
  // you can do other things here
  const result = await handler(event, context);
  // and here
  return result;
};

Usage example using the Express framework with Azure


const serverless = require('serverless-http');
const express = require('express');

const app = express();

app.use(/* register your middleware as normal */);

const handler = serverless(app, { provider: 'azure' });
module.exports.funcName = async (context, req) => {
  context.res = await handler(context, req);
}

Other examples

json-server-less-λ - using serverless-http with json-server and serverless framework in AWS

Limitations

Your code is running in a serverless environment. You cannot rely on your server being 'up' in the sense that you can/should not use in-memory sessions, web sockets, etc. You are also subject to provider specific restrictions on request/response size, duration, etc.

Think of this as a familiar way of expressing your app logic, not trying to make serverless do something it cannot.

Contributing

Pull requests are welcome! Especially test scenarios for different situations and configurations.

Further Reading

Here are some more detailed examples and advanced configuration options as well as provider-specific documentation

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 31
Method 7
Class 4
Interface 1

Languages

TypeScript100%

Modules by API surface

lib/response.js10 symbols
lib/provider/aws/create-request.js5 symbols
lib/provider/aws/clean-up-event.js4 symbols
test/integration/test-offline.js3 symbols
lib/request.js3 symbols
test/integration/test-aws.js2 symbols
lib/provider/azure/is-binary.js2 symbols
lib/provider/azure/create-request.js2 symbols
lib/provider/azure/clean-up-request.js2 symbols
lib/provider/aws/is-binary.js2 symbols
examples/hapi/src/server.js2 symbols
test/integration/cookies.js1 symbols

Dependencies from manifests, versioned

@loopback/rest11.1.2 · 1×
@types/koa2.11.0 · 1×
body-parser1.19.0 · 1×
chai4.2.0 · 1×
chai-as-promised7.1.1 · 1×
cookie-parser1.4.4 · 1×
eslint8.12.0 · 1×
eslint-plugin-mocha10.0.3 · 1×
express4.17.1 · 1×
fastify3.27.4 · 1×
get-stream5.1.0 · 1×
hapi18.1.0 · 1×

For agents

$ claude mcp add serverless-http \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page