forked from superfly/aws-lambda-express-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
28 lines (23 loc) · 737 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict'
const express = require('express')
const getRawBody = require('raw-body')
const contentType = require('content-type')
let app = express()
app.set('view engine', 'ejs');
app.all('*', (req, res, next) => {
const reqContentType = req.headers['content-type'] || 'text/plain'
const encoding = contentType.parse(reqContentType).parameters.charset
getRawBody(req, {
length: req.headers['content-length'],
limit: '1mb',
encoding: encoding
}, function (err, string) {
if (err) return next(err)
req.textBody = string.toString()
res.render('index', {req: req})
})
})
app.use((err, req, res, next)=> {
res.send(err)
})
module.exports = app // export your app so aws-serverless-express can use it