Skip to content

Instantly share code, notes, and snippets.

@BigAB
Created January 8, 2016 06:06
Show Gist options
  • Save BigAB/4d6281bd8110682db4fa to your computer and use it in GitHub Desktop.
Save BigAB/4d6281bd8110682db4fa to your computer and use it in GitHub Desktop.
Simple test of Feathers-Mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var authorSchema = new Schema({
name: String,
age: Number,
blogs: [{ type: Schema.Types.ObjectId, ref: 'Blog' }]
});
var Author = mongoose.model('Author', authorSchema);
module.exports = Author;
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;
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