summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-06-02 16:55:36 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-06-02 16:55:36 +0200
commit443bee744a867fa116ebe45f55cdedfef77ade96 (patch)
tree90f6aa9abb2d52d9730116b78fdb65149475eb04
parent0076d8ccd0598448e641a31ceee4257368ecc01d (diff)
downloadmean-app-443bee744a867fa116ebe45f55cdedfef77ade96.zip
mean-app-443bee744a867fa116ebe45f55cdedfef77ade96.tar.gz
add controllers
-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')
+};