Skip to content

Instantly share code, notes, and snippets.

@nikolaymatrosov
Last active April 3, 2021 14:40
Show Gist options
  • Save nikolaymatrosov/bf440061f96aa8627a9e1fae0d8d3278 to your computer and use it in GitHub Desktop.
Save nikolaymatrosov/bf440061f96aa8627a9e1fae0d8d3278 to your computer and use it in GitHub Desktop.
API GW Express
const express = require('express');
const serverless = require('serverless-http');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get('/api/info', (req, res) => {
res.send({ application: 'sample-app', version: '1.0' });
});
app.get('/api/pet/:name?', (req, res) => {
res.send({ ...req.params });
});
module.exports.handler = (event, context) => {
const patchedEvent = {
...event,
path: event.url,
originalPath: event.path,
}
return serverless(app)(patchedEvent, context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment