Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
f0e5bcdb
Commit
f0e5bcdb
authored
Jan 13, 2021
by
우지원
Browse files
Merge remote-tracking branch 'origin/young' into jiweon827
parents
e3e80e27
36320a85
Changes
25
Hide whitespace changes
Inline
Side-by-side
server/models/
c
hat.js
→
server/models/
C
hat.js
View file @
f0e5bcdb
...
...
@@ -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
server/models/profile.js
0 → 100644
View file @
f0e5bcdb
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
server/routes/profile.routes.js
0 → 100644
View file @
f0e5bcdb
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
server/routes/user.routes.js
View file @
f0e5bcdb
...
...
@@ -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) 을 타고 들어간것임
...
...
server/server.js
View file @
f0e5bcdb
...
...
@@ -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
(
chat
Router
)
app
.
use
(
profile
Router
)
//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
,
()
=>
{
console
.
log
(
'
Listening on port 3030
'
)
server
.
listen
(
3030
,
()
=>
{
console
.
log
(
'
Listening on port 3030
'
)
})
/////////////////////////////////////////////////////////
// export default server
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment