Skip to content

Commit

Permalink
Merge 73faa4e into 4d25340
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeio committed Oct 10, 2019
2 parents 4d25340 + 73faa4e commit a0ebf16
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 543 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
@@ -1,4 +1,5 @@
root: true
extends: standard
rules:
eol-last: error
eqeqeq: ["error", "always", { "null": "ignore" }]
Expand Down
22 changes: 15 additions & 7 deletions README.md
Expand Up @@ -17,6 +17,8 @@ $ npm install express-session

## API

<!-- eslint-disable no-unused-vars -->

```js
var session = require('express-session')
```
Expand Down Expand Up @@ -127,6 +129,9 @@ have your node.js behind a proxy and are using `secure: true`, you need to set
"trust proxy" in express:

```js
var express = require('express')
var session = require('express-session')

var app = express()
app.set('trust proxy', 1) // trust first proxy
app.use(session({
Expand All @@ -141,6 +146,9 @@ For using secure cookies in production, but allowing for testing in development,
the following is an example of enabling this setup based on `NODE_ENV` in express:

```js
var express = require('express')
var session = require('express-session')

var app = express()
var sess = {
secret: 'keyboard cat',
Expand Down Expand Up @@ -175,7 +183,7 @@ The default value is a function which uses the `uid-safe` library to generate ID

```js
app.use(session({
genid: function(req) {
genid: function (req) {
return genuuid() // use UUIDs for session IDs
},
secret: 'keyboard cat'
Expand Down Expand Up @@ -297,10 +305,10 @@ are typically fine. For example below is a user-specific view counter:

```js
// Use the session middleware
app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 } }))

// Access the session as req.session
app.get('/', function(req, res, next) {
app.get('/', function (req, res, next) {
if (req.session.views) {
req.session.views++
res.setHeader('Content-Type', 'text/html')
Expand All @@ -321,7 +329,7 @@ a new SID and `Session` instance will be initialized at `req.session`
and the `callback` will be invoked.

```js
req.session.regenerate(function(err) {
req.session.regenerate(function (err) {
// will have a new session here
})
```
Expand All @@ -332,7 +340,7 @@ Destroys the session and will unset the `req.session` property.
Once complete, the `callback` will be invoked.

```js
req.session.destroy(function(err) {
req.session.destroy(function (err) {
// cannot access session here
})
```
Expand All @@ -343,7 +351,7 @@ Reloads the session data from the store and re-populates the
`req.session` object. Once complete, the `callback` will be invoked.

```js
req.session.reload(function(err) {
req.session.reload(function (err) {
// session updated
})
```
Expand All @@ -363,7 +371,7 @@ There are some cases where it is useful to call this method, for example,
redirects, long-lived requests or in WebSockets.

```js
req.session.save(function(err) {
req.session.save(function (err) {
// session saved
})
```
Expand Down

0 comments on commit a0ebf16

Please sign in to comment.