MCPcopy
hub / github.com/dougmoscrop/serverless-http

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

repository ↗ · DeepWiki ↗ · release v4.0.0 ↗
43 symbols 95 edges 56 files 0 documented · 0%
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

FrameworkApplication (Interface)
(no doc)
serverless-http.d.ts

Core symbols most depended-on inside this repo

from
called by 17
lib/response.js
common
called by 8
lib/framework/get-framework.js
writeHead
called by 4
lib/response.js
getEventType
called by 4
lib/provider/aws/get-event-type.js
done
called by 3
lib/finish.js
body
called by 3
lib/response.js
addData
called by 2
lib/response.js
headers
called by 2
lib/response.js

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