1- const express = require ( 'express' )
2- const morgan = require ( 'morgan' ) ;
1+ const express = require ( "express" ) ;
2+ const morgan = require ( "morgan" ) ;
3+ const path = require ( "path" ) ;
34
45const app = express ( ) ;
5- app . use ( morgan ( 'dev' ) ) ;
66
7- const port = process . env . PORT || 8082 ;
7+ app . use ( morgan ( "dev" ) ) ;
8+
9+ // app.use(express.static(path.join(__dirname, "../dist")));
10+
11+ const port = process . env . PORT || 8081 ;
812const keywords = [
9- { keyword : '이탈리아' } ,
10- { keyword : '세프의요리' } ,
11- { keyword : '제철' } ,
12- { keyword : '홈파티' }
13- ]
14- const search = [ {
15- "id" : 1 ,
16- "name" : "[버거] 치즈버거처럼 생긴 새우버거" ,
17- "image" : "https://images.unsplash.com/photo-1547584370-2cc98b8b8dc8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
18- } , {
19- "id" : 2 ,
20- "name" : "[샐러드] 맛있는 색깔의 콥셀러드" ,
21- "image" : "https://images.unsplash.com/photo-1512621776951-a57141f2eefd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
22- } , {
23- "id" : 3 ,
24- "name" : "[피자] 썸네일 주소가 잘못된 상품" ,
25- "image" : "http://foo.bar/image.jpg"
26- } ]
13+ { keyword : "이탈리아" } ,
14+ { keyword : "세프의요리" } ,
15+ { keyword : "제철" } ,
16+ { keyword : "홈파티" }
17+ ] ;
18+ const search = [
19+ {
20+ id : 1 ,
21+ name : "[버거] 치즈버거처럼 생긴 새우버거" ,
22+ image :
23+ "https://images.unsplash.com/photo-1547584370-2cc98b8b8dc8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
24+ } ,
25+ {
26+ id : 2 ,
27+ name : "[샐러드] 맛있는 색깔의 콥셀러드" ,
28+ image :
29+ "https://images.unsplash.com/photo-1512621776951-a57141f2eefd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
30+ } ,
31+ {
32+ id : 3 ,
33+ name : "[피자] 썸네일 주소가 잘못된 상품" ,
34+ image : "http://foo.bar/image.jpg"
35+ }
36+ ] ;
2737let history = [
28- { " keyword" : "검색기록2" , " date" : "12.03" } ,
29- { " keyword" : "검색기록1" , " date" : "12.02" } ,
30- { " keyword" : "검색기록0" , " date" : "12.01" }
31- ]
38+ { keyword : "검색기록2" , date : "12.03" } ,
39+ { keyword : "검색기록1" , date : "12.02" } ,
40+ { keyword : "검색기록0" , date : "12.01" }
41+ ] ;
3242
33- app . get ( ' /api/keywords' , ( req , res ) => {
43+ app . get ( " /api/keywords" , ( req , res ) => {
3444 // res.header("Access-Control-Allow-Origin", "*");
35- res . json ( keywords )
36- } )
45+ res . json ( keywords ) ;
46+ } ) ;
3747
38- app . get ( ' /api/history' , ( req , res ) => {
39- res . json ( history )
40- } )
48+ app . get ( " /api/history" , ( req , res ) => {
49+ res . json ( history ) ;
50+ } ) ;
4151
42- app . post ( ' /api/history' , ( req , res ) => {
43- keyword = ( req . query . keyword || '' ) . trim ( )
44- if ( ! keyword ) return
52+ app . post ( " /api/history" , ( req , res ) => {
53+ keyword = ( req . query . keyword || "" ) . trim ( ) ;
54+ if ( ! keyword ) return ;
4555
46- history . filter ( item => item . keyword !== keyword )
56+ history . filter ( item => item . keyword !== keyword ) ;
4757
4858 history = [
49- { keyword, date : ' 12.31' } ,
59+ { keyword, date : " 12.31" } ,
5060 ...history . filter ( item => item . keyword !== keyword )
51- ]
61+ ] ;
62+
63+ res . json ( history ) ;
64+ } ) ;
5265
53- res . json ( history )
54- } )
66+ app . delete ( "/api/ history" , ( req , res ) => {
67+ const keyword = ( req . query . keyword || "" ) . trim ( ) ;
5568
56- app . delete ( '/api/history' , ( req , res ) => {
57- keyword = ( req . query . keyword || '' ) . trim ( )
69+ history = history . filter ( item => item . keyword !== keyword ) ;
70+ res . json ( history ) ;
71+ } ) ;
5872
59- history = history . filter ( item => item . keyword !== keyword )
60- res . json ( history )
61- } )
73+ app . get ( "/api/search" , ( req , res ) => {
74+ res . json ( search ) ;
75+ } ) ;
6276
63- app . get ( '/api/search' , ( req , res ) => {
64- res . json ( search )
65- } )
77+ // app.get("*" , (req, res) => {
78+ // res.sendFile(path.join(__dirname, "../dist/index.html"));
79+ // });
6680
6781app . listen ( port , ( ) => {
68- console . log ( `서버가 구동되었습니다. localhost:${ port } ` )
69- } )
82+ console . log ( `서버가 구동되었습니다. localhost:${ port } ` ) ;
83+ } ) ;
0 commit comments