Skip to content

Commit

Permalink
add Mongo to package
Browse files Browse the repository at this point in the history
  • Loading branch information
darthfiddler committed Mar 1, 2018
1 parent 63c3cdf commit eaa372f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ An object that contains:
1. run (_function_): A function to run the server.
Signature: (port, callback) => {}
2. app (_object_): The Koa app.
3. db (_object_): The `db` implementation.

### Usage

Expand Down
25 changes: 24 additions & 1 deletion docs/multiplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ you can use to attach other handlers etc.

```js
const KoaStatic = require('koa-static');
const Server = require('boardgame.io/server');
const Server = require('boardgame.io/server').Server;
const TicTacToe = require('./tic-tac-toe');

const server = Server({ games: [TicTacToe] });
Expand All @@ -93,3 +93,26 @@ Client({
multiplayer: { server: 'hostname:port' },
});
```

#### Database

The default storage implementation is an in-memory map. However,
you can provide your own adapter to connect to any backend, or
use the bundled MongoDB connector.

```js
const { Server, Mongo } = require('boardgame.io/server');
const TicTacToe = require('./tic-tac-toe');

const server = Server({
games: [TicTacToe],
db: new Mongo({
url: 'mongodb://...',
dbname: 'bgio',
}),
});

server.run(8000);
```

!> You can get a free MongoDB instance at places like mlab.com.
3 changes: 2 additions & 1 deletion packages/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
*/

import { Server } from '../src/server/index.js';
import { Mongo } from '../src/server/db.js';

export { Server };
export { Server, Mongo };

0 comments on commit eaa372f

Please sign in to comment.