summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controllers/MovieController.js15
-rw-r--r--index.js6
-rw-r--r--routes.js3
3 files changed, 24 insertions, 0 deletions
diff --git a/controllers/MovieController.js b/controllers/MovieController.js
new file mode 100644
index 0000000..5cb7681
--- /dev/null
+++ b/controllers/MovieController.js
@@ -0,0 +1,15 @@
+var restful = require('node-restful');
+
+module.exports = function(app, route) {
+
+ var rest = restful.model(
+ 'movie',
+ app.models.movie
+ ).methods(['get', 'put', 'post', 'delete']);
+
+ rest.register(app, route);
+
+ return function(req, res, next) {
+ next();
+ };
+};
diff --git a/index.js b/index.js
index 91dbd21..5a31090 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,7 @@ var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
+var _ = require('lodash');
// create express application
var app = express();
@@ -33,6 +34,11 @@ mongoose.connection.once('open', function() {
app.models = require('./models/index.js');
+ var routes = require('./routes.js');
+ _.each(routes, function(controller, route) {
+ app.use(route, controller(app, route));
+ });
+
console.log("listening on port " + port);
app.listen(port);
});
diff --git a/routes.js b/routes.js
new file mode 100644
index 0000000..5111993
--- /dev/null
+++ b/routes.js
@@ -0,0 +1,3 @@
+module.exports = {
+ 'movie': require('./controllers/MovieController')
+};