-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
165 lines (154 loc) · 4.26 KB
/
server.js
File metadata and controls
165 lines (154 loc) · 4.26 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* eslint-disable semi */
var express = require('express')
var find = require('array-find')
var data = [
{
id: 'pop',
genre: 'Pop',
member: [
{
name: 'Jose',
age: '26',
city: 'Amsterdam',
bio: 'I haven’t dated much in recent years because I’ve been so focused on my career. Now I’m ready to meet the person who will pull my head out of the books and bring me a bit of happiness.',
favMusic: [
'Imagine Dragons - Whatever it takes',
'5 Seconds Of Summer - Youngblood',
'Avicii, Aloe Blacc - SOS'
],
question: 'You should leave a comment if you like Harry Potter and want to discuss it further.'
},
]
},
{
id: 'rock',
genre: 'Rock',
member: [
{
name: 'Noah',
age: '23',
city: 'Amsterdam',
bio: 'I am Noah, an avid traveler. Would rather hike in the moutains than surf a couch.',
favMusic: [
'Live My Last - Lets get this started again',
'Red - Hold Me Now',
'Imagine Dragons - Natural'
],
question: 'If you did not have to sleep, what would you do with the extra time? I would play guitar'
}
]
},
{
id: 'jazz',
genre: 'Jazz',
member: [
{
name: 'Benjamin',
age: '22',
city: 'Roterdam',
bio: 'IT guy by day. Dancing, concerts, and camping by night',
favMusic: [
'Paul Desmonds - Take Five',
'Bard Howard - Fly Me To The Moon',
'Billy Streyhorn - The A-Train'
],
question: 'You should leave a comment if you like Harry Potter and want to discuss it further.'
}
]
},
{
id: 'metal',
genre: 'Metal',
member: [
{
name: 'Oliver',
age: '23',
city: 'Amsterveen',
bio: 'I live by myself, I pay my own rent, I wear socks that match and I love my mom. I am a confident, attractive & comedic person.',
favMusic: [
'I SEE STARS - Portals',
'Arrows to Athens - Jet Black Heart',
'Arrows to Athens - Casual'
],
question: 'You should leave a comment if you like Harry Potter and want to discuss it further.'
}
]
},
{
id: 'classical',
genre: 'Classical',
member: [
{
name: 'Lucas',
age: '25',
city: 'Den Haag',
bio: 'I am a straight forward guy. I take my career seriously. I wear socks that match. And I probably check my iPhone too much. Maybe you will forgive me for that last one thought?',
favMusic: [
'J.S. Bach—Toccata and Fugue in D Minor',
'Craig Armstrong – Romeo & Juliet Balcony Scene',
'Verdi – Libiamo Ne’Lieti Calici'
],
question: 'You should leave a comment if you like Harry Potter and want to discuss it further.'
}
]
},
{
id: 'country',
genre: 'Country',
member: [
{
name: 'James',
age: '26',
city: 'Utrecht',
bio: 'Lets say just say I dont spend a lot of time in front of the TV. Im too busy hunting down my next adventure. Next up: kitesurfing. Care to join?',
favMusic: [
'Kane Wallen - Good As You',
'Luce Combs - Beer Never Broke My Heart',
'Lee Brice - Rumor'
],
question: 'You should leave a comment if you like Harry Potter and want to discuss it further.'
}
]
}
]
express()
.use(express.static('static'))
.set('view engine', 'ejs')
.set('views', 'view')
.get('/', filter)
.get('/:id', match)
.get('/:name', profile)
.use(notFound)
.listen(3000)
//filter page
function filter(req, res) {
res.render('filter.ejs', {data: data})
}
//match page
function match(req, res, next) {
var id = req.params.id
var match = find(data, function (value) {
return value.id === id
})
if (!match) {
next()
return
}
res.render('match.ejs', {data: match})
}
//profile page
function profile(req, res, next) {
var name = req.params.member
var profile = find(data, function (value) {
return value.id.member === name
})
if (!profile) {
next()
return
}
res.render('profile.ejs', {data: profile})
}
//404 page
function notFound(req, res) {
res.status(404).render('not-found.ejs')
}