Skip to content

Commit eaa372f

Browse files
committed
add Mongo to package
1 parent 63c3cdf commit eaa372f

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

docs/api/Server.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ An object that contains:
2222
1. run (_function_): A function to run the server.
2323
Signature: (port, callback) => {}
2424
2. app (_object_): The Koa app.
25+
3. db (_object_): The `db` implementation.
2526

2627
### Usage
2728

docs/multiplayer.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ you can use to attach other handlers etc.
7474

7575
```js
7676
const KoaStatic = require('koa-static');
77-
const Server = require('boardgame.io/server');
77+
const Server = require('boardgame.io/server').Server;
7878
const TicTacToe = require('./tic-tac-toe');
7979

8080
const server = Server({ games: [TicTacToe] });
@@ -93,3 +93,26 @@ Client({
9393
multiplayer: { server: 'hostname:port' },
9494
});
9595
```
96+
97+
#### Database
98+
99+
The default storage implementation is an in-memory map. However,
100+
you can provide your own adapter to connect to any backend, or
101+
use the bundled MongoDB connector.
102+
103+
```js
104+
const { Server, Mongo } = require('boardgame.io/server');
105+
const TicTacToe = require('./tic-tac-toe');
106+
107+
const server = Server({
108+
games: [TicTacToe],
109+
db: new Mongo({
110+
url: 'mongodb://...',
111+
dbname: 'bgio',
112+
}),
113+
});
114+
115+
server.run(8000);
116+
```
117+
118+
!> You can get a free MongoDB instance at places like mlab.com.

packages/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
*/
88

99
import { Server } from '../src/server/index.js';
10+
import { Mongo } from '../src/server/db.js';
1011

11-
export { Server };
12+
export { Server, Mongo };

0 commit comments

Comments
 (0)