Skip to content

Commit f83113e

Browse files
committed
temp fix for collab
1 parent cf26dd2 commit f83113e

File tree

7 files changed

+21
-12
lines changed

7 files changed

+21
-12
lines changed

collab/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
FROM golang:1.20
22

3-
WORKDIR /collab-service
3+
WORKDIR /collab
44

55
COPY go.mod go.sum ./
66
RUN go mod download
77

88
COPY . .
99

1010
# Build
11-
RUN CGO_ENABLED=0 GOOS=linux go build -o /collab-service/app
11+
RUN CGO_ENABLED=0 GOOS=linux go build -o /collab/app
12+
13+
EXPOSE 4000
1214

1315
# Run
14-
CMD ["/collab-service/app"]
16+
CMD ["/collab/app"]

collab/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ func (h *Hub) Run() {
141141

142142
// ServeWs handles WebSocket requests
143143
func serveWs(hub *Hub, c *gin.Context, roomMappings *verify.RoomMappings) {
144+
145+
log.Println("handler called!")
144146
roomID := c.Query("roomID")
145147
if roomID == "" {
146148
http.Error(c.Writer, "roomID required", http.StatusBadRequest)
@@ -221,7 +223,7 @@ func statusHandler(hub *Hub) gin.HandlerFunc {
221223
for client := range hub.clients {
222224
roomID := client.roomID
223225
currentStatus, ok := status[roomID]
224-
if !ok {
226+
if (!ok) {
225227
// Initialize status for a new roomID
226228
status[roomID] = map[string]interface{}{
227229
"clients": 1,
@@ -251,7 +253,6 @@ func main() {
251253
REDIS_URI = "localhost:9190"
252254
}
253255
roomMappings := verify.InitialiseRoomMappings(REDIS_URI, 1)
254-
255256
// WebSocket connection endpoint
256257
r.GET("/ws", func(c *gin.Context) {
257258
serveWs(hub, c, roomMappings)

kubernetes/collab-service-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ spec:
1414
containers:
1515
- name: collab
1616
image: distractedcat/collab:1.0.0
17-
imagePullPolicy: IfNotPresent
17+
imagePullPolicy: Always
1818
env:
1919
- name: PORT
2020
value: :4000
2121
- name: REDIS_URI
2222
value: redis:6379
23-
- name: USER_SERVICE_API
23+
- name: USER_SERVICE_URI
2424
value: http://user-service:3001
2525
ports:
2626
- containerPort: 4000

kubernetes/collab-service-service.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ spec:
99
- protocol: TCP
1010
port: 4000
1111
targetPort: 4000
12-
type: ClusterIP
12+
nodePort: 31000
13+
type: NodePort

kubernetes/peerprep-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ spec:
2626
value: blob
2727
- name: NEXT_PUBLIC_NGINX
2828
value: http://nginx:80
29+
- name: NEXT_PUBLIC_COLLAB
30+
value: ws://127.0.0.1/37919
2931
- name: DEV_ENV
3032
value: not
3133
ports:

peerprep/api/gateway.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export async function fetchQuestion(
4242
};
4343
}
4444

45+
4546
// NOTE: this may cause the following: "Can't resolve canvas"
4647
// https://github.com/kkomelin/isomorphic-dompurify/issues/54
4748
const question = (await response.json()) as Question;

peerprep/components/questionpage/CollabEditor.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export default function CollabEditor({ question, roomID, authToken }: Props) {
7777

7878
console.log("Yep");
7979

80-
const newSocket = new WebSocket(`ws://localhost:4000/ws?roomID=${roomID}`);
81-
80+
const newSocket = new WebSocket(`${process.env.NEXT_PUBLIC_COLLAB}/ws?roomID=${roomID}`);
81+
8282
newSocket.onopen = () => {
8383
console.log("WebSocket connection established");
8484
setconnected(true);
@@ -112,8 +112,10 @@ export default function CollabEditor({ question, roomID, authToken }: Props) {
112112
}
113113
};
114114

115-
newSocket.onerror = () => {
116-
console.log("server down");
115+
newSocket.onerror = (event) => {
116+
console.error("WebSocket error observed:", event);
117+
console.error("WebSocket readyState:", newSocket.readyState);
118+
console.error("WebSocket URL:", newSocket.url);
117119
};
118120

119121
newSocket.onclose = () => {

0 commit comments

Comments
 (0)