서버의 역할
'*'
모든 영역에서 html 반환app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../PostSite/build/index.html'))
})
npm i mongoose --save
// 몽구스 가져와서
const mongoose = require('mongoose');
// 서버 열 때, 몽구스 적용 하도록 복붙
app.listen(port, () => {
mongoose.connect('mongodb://localhost:27017/test');
console.log(`Example app listening on port ${port}`)
})
app.listen(port, () => {
mongoose.connect('이부분 내 api 주소 가져온 것으로 변경');
console.log(`Example app listening on port ${port}`)
})
app.use(express.static(path.join(__dirname, '../PostSite/build')))
// 서버를 열고, 내주소로 변경
app.listen(port, () => {
mongoose.connect(
'내 api 서버'
// 실행이 잘 되었을 때
).then (()=>{
console.log(`Example app listening on port ${port}`)
console.log('Connecting MongoDB...')
// 실행이 잘 안되었을 때
}).catch((err)=>{
console.log(`${err}`)
})
})