Created
January 8, 2016 06:06
-
-
Save BigAB/4d6281bd8110682db4fa to your computer and use it in GitHub Desktop.
Simple test of Feathers-Mongoose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var blogSchema = new Schema({ | |
title: String, | |
author: { type: Schema.Types.ObjectId, ref: 'Author' } | |
}); | |
var Blog = mongoose.model('Blog', blogSchema); | |
module.exports = Blog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bodyParser = require('body-parser'); | |
var path = require('path'); | |
var mongoose = require('mongoose'); | |
var Blog = require('./simple-blog-model'); | |
var Author = require('./simple-author-model'); | |
var feathers = require('feathers'); | |
var hooks = require('feathers-hooks'); | |
var mongooseService = require('feathers-mongoose'); | |
var app = feathers(); | |
// Add REST API support | |
app.configure(feathers.rest()) | |
.configure(hooks()) | |
.use(bodyParser.urlencoded({ extended: true })) | |
.use(bodyParser.json()); | |
mongoose.Promise = global.Promise; | |
mongoose.connect('mongodb://localhost/simple'); | |
app.use('/blogs', mongooseService({ | |
Model: Blog | |
})); | |
app.use('/authors', mongooseService({ | |
Model: Author | |
})); | |
app.use( function(error, req, res, next) { | |
const app = req.app; | |
const code = error.code || 500; | |
res.status(code); | |
console.log(error); | |
res.format({ | |
'application/json': function () { | |
res.json(error); | |
} | |
}); | |
}); | |
app.listen(process.env.PORT || 3030); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment