50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
var express = require('express');
|
|
var app = express();
|
|
var MongoClient = require('mongodb').MongoClient, assert = require('assert');
|
|
var url = 'mongodb://localhost:27017/dat3holdetstime';
|
|
|
|
app.set('view engine', 'ejs');
|
|
app.use(express.static(__dirname + '/static'));
|
|
|
|
var mongodb;
|
|
|
|
// Connect to mongodb
|
|
MongoClient.connect(url, function(err, db) {
|
|
assert.equal(null, err);
|
|
console.log("Connected succesfully to Mongo server");
|
|
mongodb = db;
|
|
});
|
|
|
|
var getdata = function(callback) {
|
|
var collection = mongodb.collection("klandringer");
|
|
var cursor = collection.find();
|
|
cursor.toArray(function(err, result) {
|
|
if (err) {
|
|
throw err;
|
|
} else {
|
|
result.sort();
|
|
result.reverse();
|
|
// for(var i = 0; i < result.length; i++) {
|
|
// klanddata[result[i]['date']] = result[i]['data'];
|
|
// }
|
|
callback(result);
|
|
}
|
|
});
|
|
}
|
|
|
|
app.get('/', function(req, res) {
|
|
getdata(function(result) {
|
|
res.render("klandringer", {data:result});
|
|
});
|
|
});
|
|
|
|
app.get('/toc', function(req, res) {
|
|
getdata(function(result) {
|
|
res.render("indholdsfortegnelse", {data:result});
|
|
});
|
|
});
|
|
|
|
app.listen(35211, function () {
|
|
console.log('Server listening on port 35211!');
|
|
});
|