Commit f9bcb8f6 authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

1차 크롤링 완성, 상준선배 2번반복 수정필요

parent 7c1243b6
This diff is collapsed.
...@@ -37,5 +37,6 @@ ...@@ -37,5 +37,6 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
} },
"proxy":"http://localhost:3001"
} }
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh.PNG'; import ohuh from './ohuh.PNG';
import { Container, Row, Form, Image, InputGroup, Button } from 'react-bootstrap'; import { Container, Row, Form, Image, InputGroup, Button, Col } from 'react-bootstrap';
function App() { function App() {
const [state, setState] = useState(false); const [state, setState] = useState(false);
...@@ -25,28 +25,32 @@ function App() { ...@@ -25,28 +25,32 @@ function App() {
return ( return (
<Container className="vh-100"> <Container className="vh-100 d-flex justify-content-md-center align-items-center">
<Row className="d-flex justify-content-md-center"> <Col md={6} lassName=" d-flex justify-content-center">
<Image src={ohuh} /> <Row style={{marginBottom:20}}>
</Row> <Image src={ohuh} />
<Row className="d-flex justify-content-md-center"> </Row>
<Form className="vw-100" onSubmit={handleSubmit}>
<InputGroup> <Row style={{marginBottom:500}}>
<Form.Control <Form className="vw-100" onSubmit={handleSubmit}>
size="lg" <InputGroup>
placeholder="검색어를 입력하세요." <Form.Control
aria-label="Large" size="lg"
aria-describedby="inputGroup-sizing-sm" placeholder="검색어를 입력하세요."
onChange={handleChange} aria-label="Large"
/> aria-describedby="inputGroup-sizing-sm"
<InputGroup.Append> onChange={handleChange}
<Button type='submit' variant="outline-secondary">검색</Button> />
</InputGroup.Append> <InputGroup.Append>
</InputGroup> <Button type='submit' variant="outline-secondary">검색</Button>
</Form> </InputGroup.Append>
</Row> </InputGroup>
</Form>
</Row>
</Col>
</Container> </Container>
); );
} }
export default App; export default App;
\ No newline at end of file
import { Pagination } from "react-bootstrap";
import React from 'react';
function Paginations(props) {
return (
<Pagination>
<Pagination.First onClick={() => props.handlePage(1)} />
{props.index === 1 ? <Pagination.Prev onClick={()=>props.handlePage(props.index)} /> : <Pagination.Prev onClick={()=>props.handlePage(props.index - 1)} />}
{props.index === props.endPage-1 ? <Pagination.Item onClick={()=>props.handlePage(props.index - 3)}>{props.index - 3}</Pagination.Item> : ""}
{props.index === props.endPage ? <Pagination.Item onClick={()=>props.handlePage(props.index - 4)}>{props.index - 4}</Pagination.Item> : ""}
{props.index === props.endPage ? <Pagination.Item onClick={()=>props.handlePage(props.index - 3)}>{props.index - 3}</Pagination.Item> : ""}
{props.index < 3 ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index - 2)}>{props.index - 2}</Pagination.Item>}
{props.index === 1 ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index - 1)}>{props.index - 1}</Pagination.Item>}
<Pagination.Item active>{props.index}</Pagination.Item>
{props.index === props.endPage ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index + 1)}>{props.index + 1}</Pagination.Item>}
{props.index > props.endPage-2 ? "" : <Pagination.Item onClick={()=>props.handlePage(props.index + 2)}>{props.index + 2}</Pagination.Item>}
{props.index === 1 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 3)}>{props.index + 3}</Pagination.Item> : ""}
{props.index === 1 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 4)}>{props.index + 4}</Pagination.Item> : ""}
{props.index === 2 ? <Pagination.Item onClick={()=>props.handlePage(props.index + 3)}>{props.index + 3}</Pagination.Item> : ""}
{props.index === props.endPage ? "" : <Pagination.Next onClick={()=>props.handlePage(props.index + 1)} />}
<Pagination.Last onClick={() =>props.handlePage(props.endPage)} />
</Pagination>
)
}
export default Paginations
import React from 'react'; import axios from 'axios';
import { Modal, Container, Row, Col, Button } from 'react-bootstrap'; import React, { useEffect, useState } from 'react';
import { Modal, Container, Row, Col, Button, Badge, Card, Accordion, Carousel } from 'react-bootstrap';
function Place(props) { function Place(props) {
const [reviews, setReviews] = useState([])
const getReview = () => {
axios.get(`/api/review/${props.search.name}`)
.then(res => {
setReviews(res.data)
})
.catch(err => {
console.log(err)
})
}
useEffect(() => {
getReview();
}, [])
return ( return (
<> <Modal {...props}
<style type="text/css"> size="xl"
{` keyboard="true"
.modal-backdrop.in { variant="backdrop.in"
opacity: 0; // show={lgShow}
} // onHide={() => setLgShow(false)}
`} aria-labelledby="example-modal-sizes-title-lg">
</style> <Modal.Header closeButton>
<Modal {...props} <Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '40px' }}>
size="lg" {props.index + 1}. {props.search.name}
keyboard="true" </Modal.Title>
variant="backdrop.in" </Modal.Header>
// show={lgShow} <Modal.Body className="show-grid">
// onHide={() => setLgShow(false)} <Container style={{ fontSize: '40px' }}>
aria-labelledby="example-modal-sizes-title-lg"> {reviews.map((review, index) => {
<Modal.Header closeButton> return (
<Modal.Title id="contained-modal-title-vcenter"> <Row className="mt-4">
{props.search.name} <a href={review.link}>{review.title}</a>
</Modal.Title> <div>{review.summary}</div>
</Modal.Header> </Row>
<Modal.Body className="show-grid"> )
<Container> })}
<Row className="mt-4"> </Container>
<div>주도 전역을 지배하는 한라산은 남한에서 가장 높은 산으로 높이는 1,947.3m이다. 한라산이라는 이름은 산이 높아 산정에 서면 은하수를 잡아당길 있다는 뜻이며, 부악·원산·선산·두무악·영주산·부라산·혈망봉·여장군 등으로도 불려왔다.</div>
<a href="https://www.daum.net">다음의 블로그</a> {/* <Accordion defaultActiveKey="0">
<Accordion.Toggle as={Button} variant="link" eventKey="0">
<a className="mb-2">다음의 블로그 보기</a>
</Accordion.Toggle>
<Accordion.Collapse eventKey="0">
<Card.Body><div>주도 전역을 지배하는 한라산은 남한에서 가장 높은 산으로 높이는 1,947.3m이다. 한라산이라는 이름은 산이 높아 산정에 서면 은하수를 잡아당길 수 있다는 뜻이며, 부악·원산·선산·두무악·영주산·부라산·혈망봉·여장군 등으로도 불려왔다.</div></Card.Body>
</Accordion.Collapse>
<Row>
<Accordion.Toggle as={Button} variant="link" eventKey="1">
<a className="mb-2">네이버의 블로그 보기</a>
</Accordion.Toggle>
<Accordion.Collapse eventKey="1">
<Card.Body><div>한라산은 1966년 한라산 천연보호구역으로, 1970년 국립공원으로 지정되었다. 그리고 2002년에는 유네스코 생물권보전지역으로 지정되었으며 2007년에는 유네스코 세계자연유산으로 등재되었다. 2008년에는 물장오리오름 산정화구호 습지가 람사르 습지로 등록되어 보호 관리되고 있다</div></Card.Body>
</Accordion.Collapse>
</Row> </Row>
<Row className="mt-4"> <Row>
<div>한라산은 1966 한라산 천연보호구역으로, 1970 국립공원으로 지정되었다. 그리고 2002년에는 유네스코 생물권보전지역으로 지정되었으며 2007년에는 유네스코 세계자연유산으로 등재되었다. 2008년에는 물장오리오름 산정화구호 습지가 람사르 습지로 등록되어 보호 관리되고 있다</div> <Accordion.Toggle as={Button} variant="link" eventKey="2">
<a href="https://www.naver.com/">네이버의 블로그</a> <a className="mb-2">구글의 블로그 보기</a>
</Accordion.Toggle>
<Accordion.Collapse eventKey="2">
<Card.Body><div>한라산은 제주도에 있는 해발 1,947.06m, 면적 약 1,820km²의 화산으로, 제주도의 면적 대부분을 차지하고 있다. 정상에 백록담이라는 화산호가 있는데, 백록담이라는 이름은 흰 사슴이 물을 먹는 곳이라는 뜻에서 왔다고 전해진다.</div></Card.Body>
</Accordion.Collapse>
</Row> </Row>
<Row className="mt-4"> </Accordion>
<div>한라산은 제주도에 있는 해발 1,947.06m, 면적 1,820km² 화산으로, 제주도의 면적 대부분을 차지하고 있다. 정상에 백록담이라는 화산호가 있는데, 백록담이라는 이름은 사슴이 물을 먹는 곳이라는 뜻에서 왔다고 전해진다.</div> <Row style={{ color: 'white' }}>
<a href="https://www.google.com/">구글의 블로그</a></Row> <a href="https://www.daum.net/" className="mb-2">다음</a><a href="https://www.naver.com/" className="mb-2">네이버</a><a href="https://www.google.com/" className="mb-2">구글</a>
</Container> </Row>
</Modal.Body> // </Container>
<Modal.Footer> <Carousel>
<Button onClick={props.onHide}>Close</Button> <Carousel.Item interval={1000}>
</Modal.Footer> <h3>다음 블로그</h3>
</Modal> <div>주도 전역을 지배하는 한라산은 남한에서 가장 높은 산으로 높이는 1,947.3m이다. 한라산이라는 이름은 산이 높아 산정에 서면 은하수를 잡아당길 수 있다는 뜻이며, 부악·원산·선산·두무악·영주산·부라산·혈망봉·여장군 등으로도 불려왔다.</div>
</> </Carousel.Item>
<Carousel.Item interval={1000}>
<h3>네이버 블로그</h3>
<div>한라산은 1966년 한라산 천연보호구역으로, 1970년 국립공원으로 지정되었다. 그리고 2002년에는 유네스코 생물권보전지역으로 지정되었으며 2007년에는 유네스코 세계자연유산으로 등재되었다. 2008년에는 물장오리오름 산정화구호 습지가 람사르 습지로 등록되어 보호 관리되고 있다</div>
</Carousel.Item>
<Carousel.Item interval={1000}>
<h3>구글 블로그</h3>
<div>한라산은 제주도에 있는 해발 1,947.06m, 면적 약 1,820km²의 화산으로, 제주도의 면적 대부분을 차지하고 있다. 정상에 백록담이라는 화산호가 있는데, 백록담이라는 이름은 흰 사슴이 물을 먹는 곳이라는 뜻에서 왔다고 전해진다.</div>
</Carousel.Item>
</Carousel> */}
</Modal.Body>
<Modal.Footer>
<Button block onClick={props.onHide}>Close</Button>
</Modal.Footer>
</Modal>
); );
} }
export default Place; export default Place;
\ No newline at end of file
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh-sm.PNG'; import ohuh from './ohuh-sm.PNG';
import Place from './Components/Place'; import Place from './Components/Place';
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button, Pagination } from 'react-bootstrap'; import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button, Pagination } from 'react-bootstrap';
import Paginations from './Components/Paginations';
function Search(props) { function Search(props) {
const endPage = 10;
const [state, setState] = useState(false); const [state, setState] = useState(false);
const [index, setIndex] = useState(1); const [index, setIndex] = useState(1);
const [show, setShow] = useState(false); const [showSet, setShowSet] = useState([false, false, false, false]);
const [search, setSearch] = useState(props.location.state.id); const [search, setSearch] = useState(props.location.state.id);
const [mobile, setMobile] = useState();
useEffect(() => {
if (window.innerWidth < 960) {
setMobile(true)
} else {
setMobile(false)
}
}, []);
const places = [{ const places = [{
name: "한라산(hallasan)", name: "한라산(hallasan)",
address: "제주 서귀포시 토평동 산15-1", address: "제주 서귀포시 토평동 산15-1",
img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg", img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg?size=200x200",
}, { }, {
name: "성산일출봉(sungsan)", name: "성산일출봉(sungsan)",
address: "제주 서귀포시 성산읍 성산리 1", address: "제주 서귀포시 성산읍 성산리 1",
img: "https://www.jeju.go.kr/pub/site/geopark/images/sub/sub03/02%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84%EC%9D%B4%EC%95%BC%EA%B8%B0/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84_%EC%84%B1%EC%82%B0%EC%9D%BC%EC%B6%9C%EB%B4%89/1412402261.jpg", img: "https://www.jeju.go.kr/pub/site/geopark/images/sub/sub03/02%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84%EC%9D%B4%EC%95%BC%EA%B8%B0/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84_%EC%84%B1%EC%82%B0%EC%9D%BC%EC%B6%9C%EB%B4%89/1412402261.jpg?400/400",
}, { }, {
name: "해녀의 집(haenyeo)", name: "해녀의 집(haenyeo)",
address: "제주 서귀포시 성산읍 한도로 141-13지번오조리 3 오조해녀의집", address: "제주 서귀포시 성산읍 한도로 141-13지번오조리 3 오조해녀의집",
...@@ -415,6 +426,11 @@ function Search(props) { ...@@ -415,6 +426,11 @@ function Search(props) {
}} />; }} />;
} }
const handlePage = (num) => {
setIndex(num);
}
const handleChange = (e) => { const handleChange = (e) => {
setSearch(e.target.value); setSearch(e.target.value);
} }
...@@ -432,14 +448,16 @@ function Search(props) { ...@@ -432,14 +448,16 @@ function Search(props) {
return page return page
} }
const pagePlace = paginate(places, index) const pagePlace = paginate(places, index)
return ( return (
<Container> <Container >
<Row className="mt-2 mb-2"> <Link to="/" className="d-flex justify-content-center"><Image src={ohuh} /></Link>
<Form className="vw-100" onSubmit={handleSubmit}> <Row className="mb-2" className="d-flex justify-content-center">
<Form style={{ width: "90vw" }} onSubmit={handleSubmit}>
<InputGroup size="lg"> <InputGroup size="lg">
<Link to="/"><Image src={ohuh} /></Link>
<FormControl <FormControl
placeholder="검색어를 입력하세요." placeholder="검색어를 입력하세요."
value={search} value={search}
...@@ -456,38 +474,33 @@ function Search(props) { ...@@ -456,38 +474,33 @@ function Search(props) {
<Row className="d-flex flex-wrap"> <Row className="d-flex flex-wrap">
{pagePlace.map((place, index) => { {pagePlace.map((place, index) => {
return ( return (
<Col key={index} md={6}> <Col key={index} md={6} >
<Card> <Card align="center" border="info" style={{ margin: "3%" }}>
<Card.Img variant="top" src={place.img} /> <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{place.name}</Card.Title>
<Card.Body> <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={place.img} />
<Card.Title>{place.name}</Card.Title> <Card.Body >
<Card.Text> <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
{place.address} </Card.Text> {place.address} </Card.Text>
<Button variant="primary" onClick={() => setShow(true)}>{place.name} 자세히 살펴보기</Button> <Button variant="primary" onClick={() => {
<Place search={place} show={show} onHide={() => setShow(false)} /> const showArr = [false, false, false, false]
showArr[index] = true
setShowSet(showArr)
}}>{place.name} 자세히 살펴보기</Button>
<Place search={place} index={index} show={showSet[index]} onHide={() => setShowSet([false, false, false, false])} />
</Card.Body> </Card.Body>
</Card> </Card>
</Col> </Col>
) )
})} })}
</Row> </Row>
{console.log(showSet)}
{/* show가 전부 true로 바뀌어서 전부 다 보이게 되는 것이다. */}
<Row className="mt-2 d-flex justify-content-center"> <Row className="mt-2 d-flex justify-content-center">
<Pagination> <Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations>
<Pagination.First onClick={() => setIndex(1)} />
{index === 1 ? "" : <Pagination.Prev onClick={() => setIndex(index - 1)} />}
{index < 3 ? "" : <Pagination.Item onClick={() => setIndex(index - 2)}>{index - 2}</Pagination.Item>}
{index === 1 ? "" : <Pagination.Item onClick={() => setIndex(index - 1)}>{index - 1}</Pagination.Item>}
<Pagination.Item active>{index}</Pagination.Item>
{index === 10 ? "" : <Pagination.Item onClick={() => setIndex(index + 1)}>{index + 1}</Pagination.Item>}
{index > 8 ? "" : <Pagination.Item onClick={() => setIndex(index + 2)}>{index + 2}</Pagination.Item>}
{index === 10 ? "" : <Pagination.Next onClick={() => setIndex(index + 1)} />}
<Pagination.Last onClick={() => setIndex(10)} />
</Pagination>
</Row> </Row>
</Container> </Container>
); );
} }
export default Search; export default Search;
\ No newline at end of file
...@@ -4,6 +4,7 @@ import './index.css'; ...@@ -4,6 +4,7 @@ import './index.css';
import 'bootstrap/dist/css/bootstrap.min.css'; import 'bootstrap/dist/css/bootstrap.min.css';
import App from './App'; import App from './App';
import Search from './Search'; import Search from './Search';
import axios from 'axios';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
import { import {
BrowserRouter as Router, BrowserRouter as Router,
...@@ -12,13 +13,17 @@ import { ...@@ -12,13 +13,17 @@ import {
Redirect, Redirect,
} from "react-router-dom"; } from "react-router-dom";
axios.defaults.validateStatus = function (status) {
return status < 500; // default
}
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<Router> <Router>
<Switch> <Switch>
<Route exact path="/" component={App} /> <Route exact path="/" component={App} />
<Route path="/search" component={Search} /> <Route path="/search" component={Search} />
<Redirect path="/search/:id" to="/search" /> <Redirect path="/search/:search" to="/search" />
</Switch> </Switch>
</Router> </Router>
</React.StrictMode>, </React.StrictMode>,
......
This diff is collapsed.
...@@ -15,7 +15,16 @@ ...@@ -15,7 +15,16 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^0.21.1",
"charset": "^1.0.1",
"cheerio": "^1.0.0-rc.5",
"express": "^4.17.1", "express": "^4.17.1",
"iconv": "^3.0.0",
"iconv-lite": "^0.6.2",
"jschardet": "^2.2.1",
"mongoose": "^5.11.9",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"styled-components": "^5.2.1" "styled-components": "^5.2.1"
} }
} }
const config = {
env: process.env.NODE_ENV || 'development',
port: process.env.PORT || 3001,
jwtSecret: process.env.JWT_SECRET || 'My_Secret_Key',
mongoDbUri: process.env.MONGODB_URI || 'mongodb://localhost/search_page'
}
export default config
\ No newline at end of file
import Review from '../models/Review.js'
import cheerio from "cheerio";
import express from 'express';
import request from 'request-promise'
import jschardet from 'jschardet'
import iconv from 'iconv'
import fs from 'fs'
const Iconv = iconv.Iconv
const signup = async (req, res) => {
res.send("안녕하세요")
}
const search = async (req, res) => {
console.log(req.params.search)
console.log("req", req)
const url = "https://www.google.com/search?q=%ED%95%9C%EB%9D%BC%EC%82%B0%20site%3Atistory.com&oq=tistory&aqs=chrome..69i57j0l4j69i60l3.1746j0j4&sourceid=chrome&ie=UTF-8&ved=2ahUKEwis_bSFz4buAhWVdXAKHU0tBaoQ2wF6BAgIEAE&ei=T1D1X-yZD5XrwQPN2pTQCg"
request(url)
.then(anyToUtf8)
.then((html) => {
// fs.writeFileSync("googlez.txt", '\ufeff' + html, { encoding: 'utf8' });
let $ = cheerio.load(html, null, false);
let places = []
$('.kCrYT').each(function (i) {
places[i] = {
title: $(this).find('h3').text(),
link: $(this).find('a').attr('href'),
summary: $(this).find('.s3v9rd ').text(),
}
})
// console.log(places)
res.send(places)
})
function anyToUtf8(str) {
const { encoding } = jschardet.detect(str);
console.log("source encoding = " + encoding);
const iconv = new Iconv(encoding, "utf-8//translit//ignore");
return iconv.convert(str).toString();
}
// try {
// const newPlace = await new Place({
// name: req.params.search,
// address,
// img,
// })
// }
}
export default { signup, search }
\ No newline at end of file
import mongoose from 'mongoose' import mongoose from 'mongoose'
const { String, ObjectId } = mongoose.Schema.Types const { String } = mongoose.Schema.Types
const PlaceSchema = new mongoose.Schema({ const PlaceSchema = new mongoose.Schema({
name: { name: {
...@@ -17,14 +17,14 @@ const PlaceSchema = new mongoose.Schema({ ...@@ -17,14 +17,14 @@ const PlaceSchema = new mongoose.Schema({
required: true, required: true,
default: "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd", default: "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd",
}, },
search: {
type: Array,
required: true,
},
time: { time: {
type: Array, type: Array,
required: true, required: true,
}, },
review: {
type: ObjectId,
ref: 'Review'
}
}, { }, {
timestamps: true timestamps: true
}) })
......
...@@ -7,15 +7,14 @@ const ReviewSchema = new mongoose.Schema({ ...@@ -7,15 +7,14 @@ const ReviewSchema = new mongoose.Schema({
type: String, type: String,
required: true, required: true,
}, },
address: { content: {
type: String, type: String,
required: true, required: true,
unique: true, unique: true,
}, },
imag: { keyword: {
type: String, type: Array,
required: true, required: true,
default: "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd",
}, },
time: { time: {
type: Array, type: Array,
......
This diff is collapsed.
import express from 'express'
import review from '../controllers/review.controller.js'
const router = express.Router()
router.route('/api/review/:search')
.post(review.signup)
.get(review.search)
export default router
\ No newline at end of file
import express from 'express' import express from 'express'
import connectDb from './utils/connectDb.js' import connectDb from './utils/connectDb.js'
import placeRouter from './routes/place.routes.js' import placeRouter from './routes/place.routes.js'
import reviewRouter from './routes/review.routes.js'
connectDb()
const app = express() const app = express()
app.use(express.json()) app.use(express.json())
app.use(placeRouter) app.use(placeRouter)
app.use(reviewRouter)
app.get('/', (req, res) => {
console.log("/ req.body", req.body)
res.json({ message: "http://localhost3001/ 에 연결됨" })
})
app.listen(3001, () => { app.listen(3001, () => {
console.log('Server is listening on port 3001') console.log('Server is listening on port 3001')
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ async function connectDb() { ...@@ -8,7 +8,7 @@ async function connectDb() {
return return
} }
const db = await mongoose.connect(config.mongoDburi, { const db = await mongoose.connect(config.mongoDbUri, {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,
useFindAndModify: false, useFindAndModify: false,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment