koa-flash-message
Flash Messages Middleware For Koa
Last updated 4 years ago by embbnux .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install koa-flash-message 
SYNC missed versions from official npm registry.

koa-flash-message

Build Status codecov

Flash messages middleware for koa v2 application.

Installation

$ npm install koa-flash-message

koa-flash-message middleware depends on koa-generic-session. You must add koa-generic-session as a middleware prior to adding koa-flash-message

Example

import Koa from 'koa';
import session from 'koa-generic-session';
import koaRedis from 'koa-redis';
import flashMessage from 'koa-flash-message';

const redisStore = koaRedis({
  url: config.redisUrl
});

const app = new Koa();

app.keys = [config.secretKeyBase];
app.use(convert(session({
  store: redisStore,
  prefix: '__sess:',
  key: '__sid'
})));

app.use(flashMessage);

add message to flash messages

ctx.flashMessage.warning = 'Log Out Successfully!';

read all flash messages

ctx.state.flashMessage.messages
// or ctx.flashMessage.messages

read warning message

ctx.state.flashMessage.warning
// or ctx.flashMessage.warning

Full Example Code

Author

License

MIT

Current Tags

  • 0.1.6                                ...           latest (4 years ago)

7 Versions

  • 0.1.6                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (10)

Copyright 2014 - 2016 © taobao.org |