From 3f37aa7e9569ee130ff8b1e8996158737a7cb379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 2 Jun 2016 16:34:14 +0200 Subject: set minimal index.js --- index.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 index.js 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); +}); + -- cgit v1.1-2-g2b99