summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-06-02 16:34:14 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-06-02 16:34:14 +0200
commit3f37aa7e9569ee130ff8b1e8996158737a7cb379 (patch)
treec2a7398ce294c281d5f69181ca8480bfffb73802
parent94c657821c48952e16e742adc2aeece87e2c2be4 (diff)
downloadmean-app-3f37aa7e9569ee130ff8b1e8996158737a7cb379.zip
mean-app-3f37aa7e9569ee130ff8b1e8996158737a7cb379.tar.gz
set minimal index.js
-rw-r--r--index.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..329f86f
--- /dev/null
+++ b/index.js
@@ -0,0 +1,36 @@
+
+var express = require('express');
+var mongoose = require('mongoose');
+var bodyParser = require('body-parser');
+var methodOverride = require('method-override');
+
+// create express application
+var app = express();
+var port = 3000;
+
+// setup REST middleware
+app.use(bodyParser.urlencoded({extended: true}));
+app.use(bodyParser.json());
+app.use(methodOverride('X-HTTP-Method-Override'));
+
+// CORS support
+app.use(function(req, res, next) {
+ res.header('Access-Control-Allow-Origin', '*');
+ res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
+ res.header('Access-Control-Allow-Headers', 'Content-Type');
+ next();
+});
+
+// hello
+app.use('/hello', function(req, res, next) {
+ res.send('Hello World');
+ next();
+});
+
+// connect to mongodb
+mongoose.connect('mongodb://localhost/meanapp');
+mongoose.connection.once('open', function() {
+ console.log("listening on port " + port);
+ app.listen(port);
+});
+