Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@significa/directus-extension-raw-body

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@significa/directus-extension-raw-body

Simple Directus extension that sets the serialized request body in the express request object.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
2
Weekly downloads
 
Created
Source

Directus raw body extension

Simple Directus extension that sets the serialized request body in the express request object.

Installation / Configuration guide

In your Directus project directory run:

npm install @significa/directus-extension-raw-body

Create an environment variable RAW_BODY_ENDPOINT_PATTERN with a Regex Expression matching the endpoints/routes where rawBody will be added to the request object.

Examples:

# Matches all endpoints for a specific extension
RAW_BODY_ENDPOINT_PATTERN='^\/sample-extension\/.*$'

# Matches all endpoints (avoid: you should only set rawBody for custom endpoints)
RAW_BODY_ENDPOINT_PATTERN='^.*$'

# Matches two routes /hello-world and /sample/path
RAW_BODY_ENDPOINT_PATTERN='^(\/hello-world|\/sample\/path)$'

# Matches routes with variable input in path. Ex:
#  - /sample/cats/fifi
#  - /sample/cats/bob1
#  - /sample/aaaa/info
#  - /sample/bbbb/info
RAW_BODY_ENDPOINT_PATTERN='^(\/sample\/cats\/\D+|\/sample\/[a-z]+\/info)$'

Restart Directus for the changes to take effect.

Usage

Create a directus endpoint extension:

  • JS

    export default (router, _) => {
      router.post(
        '/sample',
        async (req, res, _next) => {
        console.log('Raw body:', req.rawBody)
    
         return res.json({
           status: 'OK',
           rawBody: req.rawBody,
         })
      }
    )
    
  • TS

    import { NextFunction, Request, Response, Router, } from 'express'
    import { ApiExtensionContext } from '@directus/shared/types'
    import { RequestWithRawBody } from "@significa/directus-extension-raw-body";
    
    export default (router, extensionContext: ApiExtensionContext) => {
      router.post(
        '/sample',
        async (req: RequestWithRawBody, res: Response, _next: NextFunction) => {
          console.log('Raw body:', req.rawBody)
    
          return res.json({
            status: 'OK',
            rawBody: req.rawBody,
          })
        }
      )
    })
    

Keywords

FAQs

Package last updated on 17 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc