Express
Supported versions: v4 and v5
First, you need to ensure you have the libs installed, so run this code:
npm i --save express
npm i --save-dev @types/express
Then, use the ExpressFramework when you create your adapter, like:
index.ts
import { DefaultNetwork, ServerlessAdapter } from '@h4ad/serverless-adapter';
import { ExpressFramework } from '@h4ad/serverless-adapter/frameworks/express';
const express = require('express');
const app = express();
export const handler = ServerlessAdapter.new(app)
.setNetwork(new DefaultNetwork({ setRequestIp: false }))
.setFramework(new ExpressFramework())
// continue to set the other options here.
//.setHandler(new DefaultHandler())
//.setResolver(new PromiseResolver())
//.addAdapter(new AlbAdapter())
//.addAdapter(new SQSAdapter())
//.addAdapter(new SNSAdapter())
// after put all methods necessary, just call the build method.
.build();
DefaultNetwork defines request.ip by default from the event source remote address. Express also exposes req.ip, so pass setRequestIp: false when you want Express to resolve the IP through its own request prototype and trust proxy settings. See setNetwork for the full network customization contract.
tip
Is your application instance creation asynchronous? Look the LazyFramework which helps you in asynchronous startup.
tip
Need to deal with CORS? See CorsFramework which helps you to add correct headers.