Skip to content

Commit 633b78d

Browse files
committed
protocol by env
1 parent be5b0e8 commit 633b78d

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

client/src/App.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ header {
117117
word-break: break-all;
118118
text-align: left;
119119
padding-left: 3rem;
120-
padding-right: 1rem;
120+
padding-right: 3rem;
121121
padding-top: 6rem;
122122
padding-bottom: 4rem;
123123
}
@@ -132,7 +132,16 @@ header {
132132
color: var(--prime-blue);
133133
}
134134

135+
.message-content {
136+
border: 1px solid var(--prime-blue);
137+
border-left: unset;
138+
border-bottom: unset;
139+
border-radius: 5%;
140+
margin: 2rem auto;
141+
}
142+
135143
.message-username {
144+
font-size: 0.77rem;
136145
}
137146

138147
.message-text::before {

client/src/components/Messages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const Messages: React.FC<MessageProps> = ({
4040
<div className="scroll-wrapper">
4141
<div ref={scrollRef} className="messages-container">
4242
{messages.map((message: any, idx: number) => (
43-
<div key={message._id}>
43+
<div className="message-content" key={message._id}>
4444
<p className="message-username">{message.author.username}</p>
4545
<p className="message-text">{message.text}</p>
4646
</div>

client/src/components/SessionUtils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ const SessionUtils: React.FC<any> = ({}) => {
3939
<div className="session-utils-box">
4040
<button onClick={destroySession}>END SESSION</button>
4141
{spacer()}
42-
<button onClick={getAllRooms}>FETCH ROOMS</button>
42+
{/* <button onClick={getAllRooms}>FETCH ROOMS</button>
4343
{spacer()}
4444
<button onClick={getOwnUser}>FETCH ME</button>
4545
{spacer()}
4646
<button onClick={getRecentMsgs}>FETCH MESSAGES</button>
4747
{spacer()}
48-
<button onClick={deleteAllMessages}>DELETE MESSAGES</button>
48+
<button onClick={deleteAllMessages}>DELETE MESSAGES</button> */}
4949
</div>
5050
);
5151
};

client/src/utils/hooks.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { useEffect, useState } from "react";
22
import { io, Socket } from "socket.io-client";
3-
import { API } from "../api/api";
4-
import { useRoomContext } from "./context";
3+
4+
const currentProto = window.location.protocol;
5+
const protoByEnv = currentProto === "http:" ? `http://localhost:3001` : ``;
6+
console.log(protoByEnv);
57

68
export type SocketProp = null | Socket<any, any>;
79

810
export const useChatSocket = () => {
911
const [socket, setSocket] = useState<SocketProp>(null);
1012
useEffect(() => {
1113
// Init client-specific socket connection
12-
const socket = io();
14+
const socket = io(protoByEnv);
1315
///////////////////////////////
1416
setSocket(socket);
1517
///////////////////////////////

server/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ io.on("connection", (socket) => {
3030
if (!msg) return;
3131

3232
try {
33-
socket.broadcast.emit("chat message", msg);
33+
socket.emit("chat message", msg);
3434
} catch (err) {
3535
console.error(err);
3636
}

start-debug.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd client
6+
yarn dev &
7+
cd ../server
8+
npm run debug

0 commit comments

Comments
 (0)