UNPKG

serverless-http

Version:

Use existing web application frameworks in serverless environments

24 lines (18 loc) 659 B
'use strict'; const finish = require('./lib/finish'); const getFramework = require('./lib/framework/get-framework'); const getProvider = require('./lib/provider/get-provider'); const defaultOptions = { requestId: 'x-request-id' }; module.exports = function (app, opts) { const options = Object.assign({}, defaultOptions, opts); const framework = getFramework(app); const provider = getProvider(options); return provider(async (request, ...context) => { await finish(request, options.request, ...context); const response = await framework(request); await finish(response, options.response, ...context); return response; }); };