Skip to content

Commit

Permalink
Implement basic nodejs server with routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine Emrich committed Mar 12, 2017
0 parents commit ecebd0c
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# http://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{js,html,css}]
indent_style = tab
4 changes: 4 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"node": true,
"esnext": true
}
18 changes: 18 additions & 0 deletions downloader/show-downloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const channels = require('./../models/channels');

exports.getShows = function() {
return channels.ids.map(function (channelId) {
return exports.getShow(channelId);
});
};

exports.getShow = function(channelId) {
return {
title: "The Title",
subtitle: "The Subtitle",
description: "description",
channel: channelId,
startTime: new Date().getTime(),
endTime: new Date().getTime()
};
};
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const shows = require('./routes/shows');

const app = express();

app.get('/shows', shows.findAll);
app.get('/shows/:channelId', shows.findByChannel);

app.listen(3000);
console.log('Listening on port 3000...');
36 changes: 36 additions & 0 deletions models/channels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
exports.ids = [
"das_erste",
"br_nord",
"br_sued",
"hr",
"mdr_sachsen",
"mdr_sachsen_anhalt",
"mdr_thueringen",
"ndr_hh",
"ndr_mv",
"ndr_nds",
"ndr_sh",
"rbb_berlin",
"rbb_brandenburg",
"sr",
"swr_bw",
"swr_rp",
"wdr",
"ard_alpha",
"tagesschau24",
"one",

"arte",

"zdf",
"dreisat",
"kika",
"phoenix",
"zdf_info",
"zdf_neo",

"deutsche_welle",

"parlamentsfernsehen_1",
"parlamentsfernsehen_2",
];
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "zapp-backend",
"version": "1.0.0",
"description": "Program info API for German public broadcasting services.",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Christine Coenen",
"license": "MIT",
"dependencies": {
"express": "^4.15.2"
}
}
9 changes: 9 additions & 0 deletions routes/shows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const downloader = require('./../downloader/show-downloader');

exports.findAll = function(req, res) {
res.send(downloader.getShows());
};

exports.findByChannel = function(req, res) {
res.send([downloader.getShow(req.params.channelId)]);
};

0 comments on commit ecebd0c

Please sign in to comment.