Skip to content

Commit

Permalink
updated readme, better mounted path example (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeframbach committed Jul 4, 2017
1 parent 2c24b5e commit 8b27d72
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions README.md
Expand Up @@ -53,7 +53,9 @@ or like this, for default collection `agendaJobs` and default port `3000`:

### Middleware usage

Agendash provides Express middleware you can use at a specified path, for example this will
Agendash provides Express middleware you can use at a specified path, for example this will
make Agendash available on your site at the `/dash` path. Note: Do not try to mount Agendash
at the root level like `app.use('/', Agendash(agenda))`.

```js
var express = require('express');
Expand All @@ -64,14 +66,34 @@ var app = express();
var Agenda = require('agenda');
var Agendash = require('agendash');

var agenda = new Agenda({mongo: 'mongodb://127.0.0.1/agendaDb'});
app.use('/agendash', Agendash(agenda));
var agenda = new Agenda({db: {address: 'mongodb://127.0.0.1/agendaDb'}});
// or provide your own mongo client:
// var agenda = new Agenda({mongo: myMongoClient})

app.use('/dash', Agendash(agenda));

// ... your other routes

// ... start your server
```

By mounting Agendash as middleware on a specific path, you may provide your
own authentication for that path. For example if you have an authenticated
session using passport, you can protect the dashboard path like this:

```
app.use('/dash',
function (req, res, next) {
if (!req.user || !req.user.is_admin) {
res.send(401);
} else {
next();
}
},
Agendash(agenda)
);
```

Other middlewares will come soon in the folder `/lib/middlewares/`.
You'll just have to update the last line to require the middleware you need:

Expand Down

0 comments on commit 8b27d72

Please sign in to comment.