session-flash 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +23 -34
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# session-flash
|
|
2
2
|
|
|
3
3
|
The flash is a special area of the session used for storing messages. Messages
|
|
4
4
|
are written to the flash and cleared after being displayed to the user. The
|
|
5
5
|
flash is typically used in combination with redirects, ensuring that the message
|
|
6
6
|
is available to the next page that is to be rendered.
|
|
7
7
|
|
|
8
|
-
This middleware was extracted from [Express](http://expressjs.com/) 2.x, after
|
|
9
|
-
Express 3.x removed direct support for the flash. connect-flash brings this
|
|
10
|
-
functionality back to Express 3.x, as well as any other middleware-compatible
|
|
11
|
-
framework or application. +1 for [radical reusability](http://substack.net/posts/b96642/the-node-js-aesthetic).
|
|
12
8
|
|
|
13
9
|
## Install
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
npm i session-flash
|
|
16
12
|
|
|
17
13
|
## Usage
|
|
18
14
|
|
|
19
|
-
#### Express
|
|
15
|
+
#### Express 5.x
|
|
20
16
|
|
|
21
17
|
Flash messages are stored in the session. First, setup sessions as usual by
|
|
22
18
|
enabling `cookieParser` and `session` middleware. Then, use `flash` middleware
|
|
23
|
-
provided by
|
|
19
|
+
provided by session-flash.
|
|
24
20
|
|
|
25
21
|
```javascript
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const app = express();
|
|
23
|
+
const cookieParser = require('cookie-parser');
|
|
24
|
+
const session = require('express-session');
|
|
25
|
+
const flash = require('session-flash');
|
|
26
|
+
|
|
27
|
+
app.use(cookieParser());
|
|
28
|
+
|
|
29
|
+
app.use(session({
|
|
30
|
+
secret: 'session-secret',
|
|
31
|
+
resave: false,
|
|
32
|
+
saveUninitialized: false,
|
|
33
|
+
cookie: { maxAge: 60000 }
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
app.use(flash());
|
|
37
|
+
|
|
38
|
+
|
|
28
39
|
|
|
29
|
-
app.configure(function() {
|
|
30
|
-
app.use(express.cookieParser('keyboard cat'));
|
|
31
|
-
app.use(express.session({ cookie: { maxAge: 60000 }}));
|
|
32
|
-
app.use(flash());
|
|
33
|
-
});
|
|
34
40
|
```
|
|
35
41
|
|
|
36
42
|
With the `flash` middleware in place, all requests will have a `req.flash()` function
|
|
@@ -49,25 +55,8 @@ app.get('/', function(req, res){
|
|
|
49
55
|
});
|
|
50
56
|
```
|
|
51
57
|
|
|
52
|
-
## Examples
|
|
53
|
-
|
|
54
|
-
For an example using connect-flash in an Express 3.x app, refer to the [express3](https://github.com/jaredhanson/connect-flash/tree/master/examples/express3)
|
|
55
|
-
example.
|
|
56
|
-
|
|
57
|
-
## Tests
|
|
58
|
-
|
|
59
|
-
$ npm install --dev
|
|
60
|
-
$ make test
|
|
61
|
-
|
|
62
|
-
[](http://travis-ci.org/jaredhanson/connect-flash)
|
|
63
|
-
|
|
64
|
-
## Credits
|
|
65
|
-
|
|
66
|
-
- [Jared Hanson](http://github.com/jaredhanson)
|
|
67
|
-
- [TJ Holowaychuk](https://github.com/visionmedia)
|
|
68
|
-
|
|
69
58
|
## License
|
|
70
59
|
|
|
71
|
-
[The MIT License]
|
|
60
|
+
[The MIT License]
|
|
72
61
|
|
|
73
|
-
Copyright (c) 2012-
|
|
62
|
+
Copyright (c) 2012-2026
|