Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/embbnux/koa-flash-message
Flash Messages Middleware For Koa
https://github.com/embbnux/koa-flash-message
flash flash-messages koa
Last synced: about 2 months ago
JSON representation
Flash Messages Middleware For Koa
- Host: GitHub
- URL: https://github.com/embbnux/koa-flash-message
- Owner: embbnux
- License: mit
- Created: 2017-02-07T14:08:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-06T15:51:21.000Z (about 7 years ago)
- Last Synced: 2024-11-15T22:54:48.074Z (3 months ago)
- Topics: flash, flash-messages, koa
- Language: JavaScript
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-flash-message
[![NPM Version](https://img.shields.io/npm/v/koa-flash-message.svg?style=flat-square)](https://www.npmjs.com/package/koa-flash-message)
[![Build Status](https://travis-ci.org/embbnux/koa-flash-message.svg?branch=master)](https://travis-ci.org/embbnux/koa-flash-message)
[![codecov](https://codecov.io/gh/embbnux/koa-flash-message/branch/master/graph/badge.svg)](https://codecov.io/gh/embbnux/koa-flash-message)Flash messages middleware for [koa](https://github.com/koajs/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';
import convert from 'koa-convert';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](https://github.com/embbnux/kails/blob/master/app/index.js)
## Author
* [Embbnux Ji](https://www.embbnux.com)
## License
MIT