-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (45 loc) · 1.07 KB
/
index.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
const express = require('express');
const app = express();
const path = require('path');
const redditData = require('./data.json');
app.use(express.static(path.join(__dirname,'public')));
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/views'));
app.get('/', (req, res) => {
res.render('home.ejs');
})
app.get('/cats', (req, res) => {
const cats = [
'Blue',
'Rocket',
'Monty',
'Stephanie',
'Winston'
]
res.render('cats', {
cats
})
})
app.get('/r/:subreddit', (req, res) => {
const {
subreddit
} = req.params;
const data = redditData[subreddit];
// console.log(data);
if(data){
res.render('subreddit', {
...data
});
} else {
res.render('notFound', { subreddit })
}
})
app.get('/rand', (req, res) => {
const num = Math.floor(Math.random() * 10) + 1;
res.render('random', {
num
});
})
app.listen(3000, () => {
console.log("LISTENING AT PORT 3000");
})