Skip to content

Commit 4795988

Browse files
authored
Merge pull request #137 from CS3219-AY2425S1/c-fix
add annotation to k8 session service to accept http
2 parents 858a37e + 8859878 commit 4795988

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

k8s/session-service.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ apiVersion: v1
3838
kind: Service
3939
metadata:
4040
name: session-svc
41+
annotations:
42+
cloud.google.com/app-protocols: '{"websocket":"HTTP", "audio":"HTTP"}'
4143
spec:
4244
type: LoadBalancer
4345
ports:

session-service/src/audio-service.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ interface AudioData {
1010
}
1111

1212
const app = express();
13-
app.use(cors({
14-
origin: '*',
15-
methods: ['GET', 'POST'],
16-
credentials: true,
17-
}));
13+
app.use(
14+
cors({
15+
origin: "*",
16+
methods: ["GET", "POST"],
17+
credentials: true,
18+
})
19+
);
1820

1921
const httpServer = createServer(app);
2022
const io = new Server(httpServer, {
2123
cors: {
2224
origin: "*",
2325
methods: ["GET", "POST"],
2426
credentials: true,
25-
allowedHeaders: ["*"]
27+
allowedHeaders: ["*"],
2628
},
2729
path: "/socket.io/",
2830
transports: ["websocket"],
@@ -33,7 +35,7 @@ const io = new Server(httpServer, {
3335

3436
// Add connection error handling
3537
io.engine.on("connection_error", (err) => {
36-
console.log('Connection error:', err);
38+
console.log("Connection error:", err);
3739
});
3840

3941
io.on("connection", (socket: Socket) => {
@@ -45,7 +47,7 @@ io.on("connection", (socket: Socket) => {
4547

4648
// Handle signaling data for WebRTC connections
4749
socket.on("signal", (signalData) => {
48-
console.log('Received signal data, broadcasting to others');
50+
console.log("Received signal data, broadcasting to others");
4951
socket.broadcast.emit("signal", signalData);
5052
});
5153

@@ -54,11 +56,11 @@ io.on("connection", (socket: Socket) => {
5456
});
5557
});
5658

57-
app.get('/health', (req, res) => {
58-
res.send('Server is running');
59+
app.get("/health", (req, res) => {
60+
res.send("Server is running");
5961
});
6062

6163
const PORT = process.env.AUDIO_PORT || 5555;
6264
httpServer.listen(PORT, () => {
6365
console.log(`Audio service is running on port ${PORT}`);
64-
});
66+
});

session-service/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const setupWSConnection = require("y-websocket/bin/utils").setupWSConnection;
1111
export const allowedOrigins = ["*"];
1212

1313
/**
14-
* Server INITIALIZATION and CONFIGURATION
14+
* Server INITIALIZATION and CONFIGURATION.
1515
* CORS configuration
1616
* Request body parsing
1717
*/

0 commit comments

Comments
 (0)