-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (50 loc) · 1.23 KB
/
app.js
File metadata and controls
61 lines (50 loc) · 1.23 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
57
58
59
60
// Generated by CoffeeScript 1.9.3
/**
* @author Pedro Mello (MushDigital)
* @email: [email protected]
* @Date: 2015-08-20
* Mi9 Code Chalenge
*/
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var port = process.env.PORT || 3000;
var host = process.env.YOUR_HOST || 'localhost';
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(function(error, request, response, next) {
response.status(400).send({
error: 'Could not decode request: JSON parsing failed'
});
response.end();
});
app.get('/', function(request, response) {
response.send('API is running');
});
app.post('/', function(request, response) {
var i, len, ref, selected, show;
selected = [];
ref = request.body.payload;
if(ref)
{
for (i = 0, len = ref.length; i < len; i++) {
show = ref[i];
if (show.drm && parseInt(show.episodeCount) > 0) {
selected.push({
image: show.image.showImage,
slug: show.slug,
title: show.title
});
}
}
}
response.send({
response: selected
});
});
app.listen(port, function(err) {
console.log("Server started on " + port);
});
module.exports = app;