Commit ce7da914 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat(cmn): keep raw body in requests (#3550)

Minor modification that puts the raw body as a string on the request
object. Useful for applications where the raw body is required rather
than the parsed JSON body as given by bodyParser. For example, this is
useful when verifying GitHub webhooks.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent dee70742
---
'@eth-optimism/common-ts': patch
---
Minor update to BaseServiceV2 to keep the raw body around when requests are made.
...@@ -386,9 +386,17 @@ export abstract class BaseServiceV2< ...@@ -386,9 +386,17 @@ export abstract class BaseServiceV2<
const app = express() const app = express()
// Body parsing. // Body parsing.
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true })) app.use(bodyParser.urlencoded({ extended: true }))
// Keep the raw body around in case the application needs it.
app.use(
bodyParser.json({
verify: (req, res, buf, encoding) => {
;(req as any).rawBody = buf?.toString(encoding || 'utf8') || ''
},
})
)
// Logging. // Logging.
app.use( app.use(
morgan('short', { morgan('short', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment