-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (55 loc) · 1.97 KB
/
app.js
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
61
62
63
64
65
66
67
68
const express = require('express');
const Reddit = require('./src/services/reddit');
const slidesService = require('./src/services/googleSlides');
const createRandomPerson = require('./src/services/createRandomPerson');
const Person = require('./src/entities/Person');
const Slide = require('./src/entities/Slide');
const app = express();
const reddit = new Reddit();
// respond with "hello world" when a GET request is made to the homepage
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.get('/reddit/', function (req, res) {
res.send(reddit.get());
});
app.get('/reddit/auth', function (req, res) {
reddit.auth().then(result => res.send(result));
});
app.get('/reddit/r/:sub' , function (req, res) {
reddit.subreddit(req.params.sub).then(presentation => {
slidesService.newPresentation(presentation).then((url) => {
res.send(url);
});
});
});
app.get('/reddit/r/:sub/top' , function (req, res) {
reddit.subreddit(req.params.sub).then(presentation => {
slidesService.newPresentation(presentation).then((url) => {
res.send(url);
});
});
});
app.get('/reddit/r/:sub/hot' , function (req, res) {
reddit.subreddit(req.params.sub).then(presentation => {
slidesService.newPresentation(presentation).then((url) => {
res.send(url);
});
});
});
app.get('/reddit/random' , function (req, res) {
reddit.random().then(presentation => {
slidesService.newPresentation(presentation).then((url) => {
res.send(url);
});
});
});
app.get('/reddit/autocomplete', function (req, res) {
res.send(reddit.autocomplete(req.query.q).then(completions => console.log(completions)));
});
app.get('/person/', function (req, res) {
res.send(createRandomPerson.get())
});
app.listen(3000, () => console.log('Whackaoke-API listening on port 3000!'))