-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (50 loc) · 1.44 KB
/
app.js
File metadata and controls
56 lines (50 loc) · 1.44 KB
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
var express = require('express');
var app = express();
var Slack = require('./code/slack');
var Utils = require('./code/utils');
var favicon = require('serve-favicon');
// default Heroku setup
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(favicon(__dirname + '/public/favicon.ico'));
// routes
app.get('/', function(req, res) {
res.render('pages/index', {
currentTick: Utils.getCurrentTick()
});
});
app.get('/api/slack/slumpvard', function(req, res) {
// TODO: dynamically route the last part of the url to a slack command, like if path is slack_commands/<variable> match that to slack.<variable>()
var msg = Slack.commands.slumpvard();
res.json(msg);
});
app.get('/api/tick', function(req, res) {
var tick = Utils.getCurrentTick();
var msg = {
tick: tick
}
res.json(msg);
});
// 404 handling
app.use(function(req, res, next) {
res.status(404);
if (req.accepts('html')) {
res.render('pages/404', {
url: req.url
});
return;
}
if (req.accepts('json')) {
res.json({
error: '404 Not found'
});
return;
}
// default to plain-text. send()
res.type('txt').send('404 Not found');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});