@u4da3/express-redirect-flash
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

express-redirect-flash

Build Status

This middlware meke it possible to redirect requests with flash attributes.

Install

npm i @u4da3/express-redirect-flash

Syntax

res.redirectFlash([status,] url, data)

Usage

app.js

const session = require('express-session')
const redirectFlash = require('@u4da3/express-redirect-flash')

app.use(session({
  // some options
}))
app.use(redirectFlash())

router.js

router.post('/update' (req, res) => {
  // update resources in the database

  // redirect with the flash attributes
  res.redirectFlash(302, 'show', {
    key1: 'value1',
    key2: 'value2'
  })
})

router.get('/show',  (req, res) => {
  // Get the flash attribute `key1`
  const v1 = res.locals.key1

  // render with the flash attributes
  res.render('resources')
})

PRG Pattern

express-redirect-flash make it easer to implement applications with the PRG pattern (Post-Redirect-Get pattern) for security.

sequence dialog

Package Sidebar

Install

npm i @u4da3/express-redirect-flash

Weekly Downloads

0

Version

0.2.0

License

Apache-2.0

Unpacked Size

33.2 kB

Total Files

12

Last publish

Collaborators

  • u4da3