-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
104 lines (83 loc) · 2.26 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Generated by CoffeeScript 1.10.0
var app, compile, events, express, moment, mongoose, nib, stylus;
express = require('express');
stylus = require('stylus');
nib = require('nib');
mongoose = require('mongoose');
moment = require('moment');
events = require('./controller/events');
app = express();
compile = function(str, path) {
return stylus(str).set('filename', path).use(nib());
};
app.configure(function() {
app.set('port', process.env.PORT || 4000);
app.set('storage-uri', process.env.MONGOHQ_URL || 'mongodb://localhost/events');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(stylus.middleware({
src: __dirname + '/public',
compile: compile
}));
return app.use(express["static"](__dirname + '/public'));
});
mongoose.connect(app.get('storage-uri'), {
db: {
safe: true
}
}, function(err) {
if (err != null) {
console.log("Mongoose - connection error: " + err);
}
return console.log("Mongoose - connection OK");
});
require('./model/event');
app.get('/', function(req, res) {
return res.render('index', {
title: 'Event finden'
});
});
app.get('/events/:id', function(req, res) {
var Resource;
Resource = mongoose.model('Event');
return Resource.findById(req.params.id, function(err, data) {
return res.render('detail', {
title: data.name,
e: data,
moment: moment
});
});
});
app.get('/events', function(req, res) {
var Resource;
Resource = mongoose.model('Event');
return Resource.find({
category: {
$in: req.query.was
}
}).sort({
date: 1
}).exec(function(err, data) {
return res.render('list', {
title: 'Ergebnisse deiner Suche',
events: data,
moment: moment
});
});
});
app.get('/create', function(req, res) {
return res.render('create', {
title: 'Event erstellen'
});
});
app.post('/api/events', events.create);
app.get('/api/events', events.retrieve);
app.get('/api/events/:id', events.retrieve);
app.put('/api/events/:id', events.update);
app["delete"]('/api/events/:id', events["delete"]);
app.listen(app.get('port'), function() {
return console.log("Listening on port " + (app.get('port')));
});