1
+ const express = require ( 'express' )
2
+ const app = express ( ) ;
3
+ const port = process . env . PORT || 8082 ;
4
+ const keywords = [
5
+ { keyword : '이탈리아' } ,
6
+ { keyword : '세프의요리' } ,
7
+ { keyword : '제철' } ,
8
+ { keyword : '홈파티' }
9
+ ]
10
+ const search = [ {
11
+ "id" : 1 ,
12
+ "name" : "[버거] 치즈버거처럼 생긴 새우버거" ,
13
+ "image" : "https://images.unsplash.com/photo-1547584370-2cc98b8b8dc8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
14
+ } , {
15
+ "id" : 2 ,
16
+ "name" : "[샐러드] 맛있는 색깔의 콥셀러드" ,
17
+ "image" : "https://images.unsplash.com/photo-1512621776951-a57141f2eefd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
18
+ } , {
19
+ "id" : 3 ,
20
+ "name" : "[피자] 썸네일 주소가 잘못된 상품" ,
21
+ "image" : "http://foo.bar/image.jpg"
22
+ } ]
23
+ let history = [
24
+ { "keyword" : "검색기록2" , "date" : "12.03" } ,
25
+ { "keyword" : "검색기록1" , "date" : "12.02" } ,
26
+ { "keyword" : "검색기록0" , "date" : "12.01" }
27
+ ]
28
+
29
+ app . get ( '/api/keywords' , ( req , res ) => {
30
+ res . json ( keywords )
31
+ } )
32
+
33
+ app . get ( '/api/history' , ( req , res ) => {
34
+ res . json ( history )
35
+ } )
36
+
37
+ app . post ( '/api/history' , ( req , res ) => {
38
+ keyword = ( req . query . keyword || '' ) . trim ( )
39
+ if ( ! keyword ) return
40
+
41
+ history . filter ( item => item . keyword !== keyword )
42
+
43
+ history = [
44
+ { keyword, date : '12.31' } ,
45
+ ...history . filter ( item => item . keyword !== keyword )
46
+ ]
47
+
48
+ res . json ( history )
49
+ } )
50
+
51
+ app . delete ( '/api/history' , ( req , res ) => {
52
+ keyword = ( req . query . keyword || '' ) . trim ( )
53
+
54
+ history = history . filter ( item => item . keyword !== keyword )
55
+ res . json ( history )
56
+ } )
57
+
58
+ app . get ( '/api/search' , ( req , res ) => {
59
+ res . json ( search )
60
+ } )
61
+
62
+ app . listen ( port , ( ) => {
63
+ console . log ( `서버가 구동되었습니다. localhost:${ port } ` )
64
+ } )
0 commit comments