-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (47 loc) · 1.62 KB
/
server.js
File metadata and controls
54 lines (47 loc) · 1.62 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
var express = require('express'); // useful for serving web content
var app = express(); // useful for serving web content
var models = require('./tripvizmodels'); // our models (connect to db)
var RSVP = require('rsvp'); // helpful promise library
// var Sequelize = require('sequelize')
// , sequelize = new Sequelize('gpptripviz', 'gpptripviz', 'gpptripviz', {
// logging: function(){}
// }); //connection to database
var PORT = 3010;
// if someone makes a HTTP GET request to our server/tweets then this
// function will attempt to send them all the tweets, or will send an error message
app.get('/tweets', function (req, res) {
models.Tweet.findAll({
include: [models.User, models.Media, models.Location],
sort: 'dateTime DESC'
})
.then(function (tweets) {
res.status(200).json(tweets);
})
.catch(function (error) {
res.status(404).send(error);
});
});
app.get('/locations', function (req, res) {
models.Location.findAll({
order: 'order_pos'
})
.then(function(locations) {
res.status(200).json(locations);
})
.catch(function(error) {
console.error('locations not found!');
res.status(500).send(error);
})
});
// if someone just makes a file request, get the files from the <project directory>/app folder
app.use(express.static(__dirname + '/app'));
// start the server on port 3000
models.start()
.then(function () {
app.listen(PORT, function() {
console.log('Listening on port %d', PORT);
});
})
.catch(function (error) {
console.error(error);
});