2017-02-18 19:57:45 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var express = require('express');
|
|
|
|
var mongo = require('mongodb');
|
|
|
|
var mongoose = require('mongoose');
|
|
|
|
|
|
|
|
var cors = require('cors');
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
// Basic Configuration
|
|
|
|
var port = process.env.PORT || 3000;
|
|
|
|
|
|
|
|
/** this project needs a db !! **/
|
2018-11-29 19:34:34 +01:00
|
|
|
mongoose.connect(process.env.MONGOLAB_URI, { useMongoClient: true });
|
2017-02-18 19:57:45 +01:00
|
|
|
|
|
|
|
app.use(cors());
|
|
|
|
|
|
|
|
/** this project needs to parse POST bodies **/
|
|
|
|
// you should mount the body-parser here
|
|
|
|
|
|
|
|
app.use('/public', express.static(process.cwd() + '/public'));
|
|
|
|
|
|
|
|
app.get('/', function(req, res){
|
|
|
|
res.sendFile(process.cwd() + '/views/index.html');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// your first API endpoint...
|
|
|
|
app.get("/api/hello", function (req, res) {
|
|
|
|
res.json({greeting: 'hello API'});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.listen(port, function () {
|
|
|
|
console.log('Node.js listening ...');
|
2018-11-29 19:34:34 +01:00
|
|
|
});
|