forked from devleague/omnimood
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (45 loc) · 1.4 KB
/
server.js
File metadata and controls
55 lines (45 loc) · 1.4 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
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const MONGO_URL = 'mongodb://localhost/omnimood';
const connection = mongoose.connect(MONGO_URL);
const Country = require('./models/countries');
const Timeline = require('./models/timeline');
const secrets = require('./json/secret.json');
const mood = require('./public/js/mood.js');
const path = require('path');
var tweets = require('./twitter.js');
const http = require('http');
app.use(express.static(__dirname + '/public'));
app.get('/timeline', (req,res)=>{
res.sendFile(path.join(__dirname+'/public/timeline.html'));
});
app.get('/graphs', (req, res)=>{
res.sendFile(path.join(__dirname+'/public/graphs.html'));
});
app.get('/api/countries', (req, res) => {
Country
.find({})
.then(results => res.json(results));
});
app.get('/api/tweets', (req, res) => {
res.json(tweets.tweets);
});
app.get('/api/timeline', (req, res) =>{
Timeline.findOne({}).then((data)=>{
res.json(data);
});
});
app.get('/flatmapping', (req, res)=>{
res.sendFile(path.join(__dirname+'/public/flatmapping.html'));
});
mongoose.connection.once('open', () => {
const server = app.listen(3000, function() {
var port = server.address().port;
console.log('Listening on port ' + port);
});
const io = require('socket.io').listen(server);
io.on('connection', (socket) => {
tweets.listenForTweets(socket);
});
});