Adapter for web frameworks (Express, Koa) to run on serverless platforms across multiple cloud providers with automatic provider detection.
| Provider | Service | Status | Trigger Type |
|---|---|---|---|
| Alibaba Cloud (Aliyun) | Function Compute | ✅ Supported | API Gateway |
| Tencent Cloud | Serverless Cloud Function (SCF) | ✅ Supported | API Gateway |
| Volcengine | veFaaS (函数服务) | ✅ Supported | API Gateway |
| Framework | Version | Status |
|---|---|---|
| Express | 4.x | ✅ Supported |
| Express | 5.x | ✅ Supported |
| Koa | 2.x | ✅ Supported |
| Koa | 3.x | ✅ Supported |
- Node.js >= 16.x
npm install @geek-fun/serverless-adapterThe adapter automatically detects the cloud provider based on the context object:
import express from 'express';
import serverlessAdapter from '@geek-fun/serverless-adapter';
const app = express();
app.get('/', (req, res) => {
res.json({ message: 'Hello World!' });
});
// Auto-detect provider based on context
export const handler = serverlessAdapter(app);You can explicitly specify the provider:
import express from 'express';
import serverlessAdapter from '@geek-fun/serverless-adapter';
const app = express();
app.get('/', (req, res) => {
res.json({ message: 'Hello from Tencent Cloud!' });
});
// Explicitly specify Tencent provider
export const main_handler = serverlessAdapter(app, { provider: 'tencent' });import express from 'express';
import serverlessAdapter from '@geek-fun/serverless-adapter';
const app = express();
app.get('/api/users', (req, res) => {
res.json({ users: [] });
});
// Handler for Aliyun Function Compute
export const handler = serverlessAdapter(app);import express from 'express';
import serverlessAdapter from '@geek-fun/serverless-adapter';
const app = express();
app.get('/api/users', (req, res) => {
res.json({ users: [] });
});
// Handler for Tencent SCF
export const main_handler = serverlessAdapter(app, { provider: 'tencent' });import express from 'express';
import serverlessAdapter from '@geek-fun/serverless-adapter';
const app = express();
app.get('/api/users', (req, res) => {
res.json({ users: [] });
});
// Handler for Volcengine veFaaS
export const handler = serverlessAdapter(app, { provider: 'volcengine' });Creates a serverless handler for your Express or Koa application.
| Parameter | Type | Required | Description |
|---|---|---|---|
app |
Express | Koa |
Yes | Express or Koa application instance |
options.provider |
'aliyun' | 'tencent' | 'volcengine' |
No | Explicitly specify cloud provider (auto-detected if omitted) |
A function that handles serverless events:
(event: Buffer, context: ProviderContext) =>
Promise<{
statusCode: number;
body: string;
headers: Record<string, string>;
isBase64Encoded: boolean;
}>;The adapter automatically detects the cloud provider by examining the context object:
| Provider | Detection Fields |
|---|---|
| Aliyun | service.name, tracing, logger, function.memory |
| Tencent | tencentcloud_region, tencentcloud_appid, namespace |
| Volcengine | requestId, region, function.memoryMb |