Commit f0e5bcdb authored by 우지원's avatar 우지원
Browse files

Merge remote-tracking branch 'origin/young' into jiweon827

parents e3e80e27 36320a85
......@@ -25,4 +25,4 @@ const ChatSchema = new mongoose.Schema({
timestamps: true
})
export default mongoose.models.Chat || mongoose.model('Chat', ChatSchema)
\ No newline at end of file
export default mongoose.models.ChatSchema || mongoose.model('chat', ChatSchema)
\ No newline at end of file
import mongoose from 'mongoose'
const { String } = mongoose.Schema.Types
const ProfileSchema = new mongoose.Schema({
defaultImg: {
type: String,
required: true,
},
}, {
timestamps: true
})
export default mongoose.models.ProfileSchema || mongoose.model('profile', ProfileSchema)
\ No newline at end of file
import express from 'express'
import profileCtrl from "../controllers/profile.controller.js";
const router = express.Router()
router.route('/profile')
.get(profileCtrl.getimage)
export default router
\ No newline at end of file
......@@ -6,11 +6,18 @@ const router = express.Router()
router.route('/users/signup')
.post(userCtrl.signup)
.get(userCtrl.hello)
router.route(`/users/:userId`)
.post(userCtrl.logineduser)
.put(userCtrl.changenick)
// router.route('/api/users/signup/:userId') //로그인한 사람의 정보만 가져오도록
// .get
router.route('/users/:userId')
.get(userCtrl.loginNavbar)
// router.param('userId', userCtrl.userById)
// /api/users/signup로 들어오는 것을 post (method) 를 통해 useCtrl.signup 이것이 처리함
//browser에서 주소창에 치고 들어가면 get (method) 을 타고 들어간것임
......
......@@ -2,30 +2,70 @@ import express from 'express'
import connectDb from './utils/connectDb.js'
import userRouter from './routes/user.routes.js'
import authRouter from './routes/auth.routes.js'
import chatRouter from './routes/chat.routers.js'
import profileRouter from './routes/profile.routes.js'
import cors from "cors";
import bodyParser from "body-parser";
import http from "http";
import { Server } from 'socket.io';
connectDb()
const app = express()
app.use(express.json())
const server = http.createServer(app);
const io = new Server(server)
io.on("connection", (socket) => { // 기본 연결
console.log("socket connect ok", socket.id)
socket.on('joinRoom', (data) => { // joinRoom을 클라이언트가 emit했을 때
let roomName = data;
console.log(roomName, "방 입장")
socket.join(roomName); //클라이언트에서 data에 적힌 room으로 참여시킴
});
socket.on('chat', (data) => {
console.log(`chat실행 :`, data.roomName, data.msg)
io.to(data.roomName).emit('broadcast', data.msg); //roomName에 존재하는 모든 소켓들에게
})
socket.on('disconnect', () => {
console.log('disconnected from server id=', socket.id)
})
});
// app.use(express.json())
//이부분을 body 파싱함
app.use(bodyParser.json());
// app.use(cors());
// app.use('/', indexRouter);
//express가 req.body라는곳을 자동으로만들어서 json형식으로 보낸것을 객체형식으로 넣음
//이부분 다음부터는 req.body라는 부분을 실행할 수 있음
app.use(userRouter)
app.use(authRouter)
app.use(chatRouter)
app.use(profileRouter)
//userRouter로 이동
// app.post('/makeChat', (req, res) => {
// app.use(chatRouter)
// })
// app.get('/', (req, res) => {
// res.send('Hello World. 안녕하세요')
// })
app.get('/', (req, res) => {
res.send('Hello World. 안녕하세요')
})
app.listen(3030, () => {
server.listen(3030, () => {
console.log('Listening on port 3030')
})
/////////////////////////////////////////////////////////
// export default server
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