forked from feathersjs-ecosystem/feathers-mongoose
/
app.js
50 lines (41 loc) · 1.33 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const feathers = require('feathers');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const handler = require('feathers-errors/handler');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const mongooseService = require('../lib');
// Require your models
const Message = require('./models/message');
// Tell mongoose to use native promises
// See http://mongoosejs.com/docs/promises.html
mongoose.Promise = global.Promise;
// Connect to your MongoDB instance(s)
mongoose.connect('mongodb://localhost:27017/feathers');
// Create a feathers instance.
const app = feathers()
// Enable Socket.io
.configure(socketio())
// Enable REST services
.configure(rest())
// Turn on JSON parser for REST services
.use(bodyParser.json())
// Turn on URL-encoded parser for REST services
.use(bodyParser.urlencoded({extended: true}));
// Connect to the db, create and register a Feathers service.
app.use('messages', mongooseService({
name: 'message',
Model: Message,
paginate: {
default: 2,
max: 4
}
}));
// A basic error handler, just like Express
app.use(handler());
// Start the server if we're not being required in a test
if (!module.parent) {
app.listen(3030);
console.log('Feathers Message mongoose service running on 127.0.0.1:3030');
}
module.exports = app;