File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed
Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "data" : {
3+ "title" : " JavaScript Flashcards" ,
4+ "cards" : [
5+ {
6+ "question" : " What language are Express apps written in?" ,
7+ "hint" : " It starts with a \" J\" " ,
8+ "answer" : " JavaScript"
9+ },
10+ {
11+ "question" : " What is one way a website can store data in a user's browser?" ,
12+ "hint" : " They are delicious with milk" ,
13+ "answer" : " Cookies"
14+ },
15+ {
16+ "question" : " What is a common way to shorten the response object's name inside middleware?" ,
17+ "hint" : " It has the same abbreviation as \" resolution\" " ,
18+ "answer" : " res"
19+ },
20+ {
21+ "question" : " How many different values can booleans have?" ,
22+ "hint" : " Think: binary" ,
23+ "answer" : " 2"
24+ },
25+ {
26+ "question" : " Which HTML element can contain JavaScript?" ,
27+ "hint" : " It starts with an \" s\" " ,
28+ "answer" : " <script>"
29+ }
30+ ]
31+ }
32+ }
Original file line number Diff line number Diff line change 11const express = require ( 'express' )
22const router = express . Router ( )
33const eyes = require ( 'eyespect' )
4+ const { data } = require ( '../data/flashcardData.json' )
5+ const { cards } = data
46
5- router . get ( '/' , ( req , res ) => {
6- eyes . inspect ( res . locals , 'res.locals' )
7+ router . get ( '/:id' , ( req , res ) => {
8+ res . render ( 'card' , {
9+ prompt : cards [ req . params . id ] . question ,
10+ hint : cards [ req . params . id ] . hint ,
11+ } )
12+ } )
13+
14+ // Sample testing req.params
15+ router . get ( '/:foo/:bar' , ( req , res ) => {
16+ eyes . inspect ( req . params , 'req.params' ) // http://expressjs.com/en/api.html#req.params
717
818 res . render ( 'card' , {
9- prompt : `Who is buried in Grant's tomb?` ,
19+ prompt : cards [ req . params . foo ] . question ,
20+ hint : cards [ req . params . bar ] . hint ,
1021 } )
1122} )
1223
You can’t perform that action at this time.
0 commit comments