Simple api builder for serverless lambda nodejs.
npm install nodejs-lambda-api
const { api } = require("nodejs-lambda-api");
const app = api();
app.use((req, res, next)=> {
//Set Headers
res.setHeaders("Access-Control-Allow-Origin","*")
next()
});
app.use((req, res, next) => {
next()
});
app.get("/", (req, res, next) => {
res.status(200)
res.json({ data: "success" })
})
app.post("/", (req, res, next) => {
const response = {
body: JSON.stringify({
message: "posted successfully",
input: req.body
})
};
res.status(200)
res.json(response)
})
app.use(function(req, res, next) {
res.status(404)
res.send()
});
app.use(function(err, req, res, next) {
res.status(500)
res.send()
});
module.exports.handle = app.handle
- Set method to ANY
- app.use
- app.get
- app.post
- app.patch
- app.delete
- app.update