Merge branch 'develop' of http://khuhub.khu.ac.kr/2020105578/nodejs-game into develop
Showing
3 changed files
with
10 additions
and
5 deletions
... | @@ -14,7 +14,11 @@ export class Server { | ... | @@ -14,7 +14,11 @@ export class Server { |
14 | 14 | ||
15 | const app = express(); | 15 | const app = express(); |
16 | const server = createServer(app); | 16 | const server = createServer(app); |
17 | - this.io = new socketIo.Server(server); | 17 | + this.io = new socketIo.Server(server, { |
18 | + cors: { | ||
19 | + origin: '*' | ||
20 | + } | ||
21 | + }); | ||
18 | 22 | ||
19 | const roomManager = new RoomManager(); | 23 | const roomManager = new RoomManager(); |
20 | 24 | ... | ... |
... | @@ -21,7 +21,7 @@ export const Login: React.FC = () => { | ... | @@ -21,7 +21,7 @@ export const Login: React.FC = () => { |
21 | console.error('login error!'); // TODO: 팝업 에러? | 21 | console.error('login error!'); // TODO: 팝업 에러? |
22 | } | 22 | } |
23 | }); | 23 | }); |
24 | - }, []); | 24 | + }, [username]); |
25 | 25 | ||
26 | return ( | 26 | return ( |
27 | <Main> | 27 | <Main> | ... | ... |
1 | import React, { useCallback, useContext, useEffect, useState } from 'react'; | 1 | import React, { useCallback, useContext, useEffect, useState } from 'react'; |
2 | +import { useHistory } from 'react-router'; | ||
2 | import { Main } from '../components/common/Main'; | 3 | import { Main } from '../components/common/Main'; |
3 | import { MessageResponse, MessageType, RawMessage } from '../components/common/types'; | 4 | import { MessageResponse, MessageType, RawMessage } from '../components/common/types'; |
4 | import { RoomBlock } from '../components/rooms/RoomBlock'; | 5 | import { RoomBlock } from '../components/rooms/RoomBlock'; |
... | @@ -6,6 +7,7 @@ import { Room } from '../components/rooms/types'; | ... | @@ -6,6 +7,7 @@ import { Room } from '../components/rooms/types'; |
6 | import SocketContext from '../contexts/SocketContext'; | 7 | import SocketContext from '../contexts/SocketContext'; |
7 | 8 | ||
8 | export const Rooms: React.FC = () => { | 9 | export const Rooms: React.FC = () => { |
10 | + const history = useHistory(); | ||
9 | const socket = useContext(SocketContext); | 11 | const socket = useContext(SocketContext); |
10 | const [ rooms, setRooms ] = useState<Room[]>([]); | 12 | const [ rooms, setRooms ] = useState<Room[]>([]); |
11 | 13 | ||
... | @@ -18,9 +20,8 @@ export const Rooms: React.FC = () => { | ... | @@ -18,9 +20,8 @@ export const Rooms: React.FC = () => { |
18 | if (response.ok) { | 20 | if (response.ok) { |
19 | setRooms(response.result!); | 21 | setRooms(response.result!); |
20 | } else { | 22 | } else { |
21 | - // TODO: 에러 핸들링 | 23 | + // 로그인하지 않고 방 목록으로 왔다고 판단 |
22 | - console.log("방 목록을 수신하지 못함"); | 24 | + history.push('/'); |
23 | - console.log(response); | ||
24 | } | 25 | } |
25 | }); | 26 | }); |
26 | }, []); | 27 | }, []); | ... | ... |
-
Please register or login to post a comment