1 year ago
#384929

Teoman Kirac
can't get socket.io to load correctly in a cloud run container
I have a new path to my site. The new path is deployed with gcloud run deploy. This path is a container and I am trying to get socket.io to work with it. I can only load a CDN in its place currently.
The path of this is "bar" in mydomain.com/foo/bar.
"foo" is the cloud run container, and "bar" is a path of the container. I think this has to be routed in express, in the cloud run container, right?
"bar" is where i want this <script src="/socket.io/socket.io.js> to work.
my paths in the load balancers page in the google console is "/foo" and "foo/bar". Is this correct? I had foo/* and foo/bar/* in addition to the others, but have since deleted them. My reasoning is that the cloud run container is what dictates the routes.
My public/index.html:
```
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/hypercollective/libraries/hls.min.js"></script>
<script src = '/hypercollective/libraries/p5.min.js'></script>
<script src="/hypercollective/libraries/addons/p5.clickable.js"></script>
<script src="submission.js"></script>
<script src="backgroundObj.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<meta charset="utf-8" />
</head>
<body>
<audio id = "audio" controls loop></audio>
<script src="sketch.js"></script>
</body>
</html>
```
my public/bar/index.html is:
```
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/hypercollective/libraries/p5.min.js"></script>
<script src="/hypercollective/libraries/addons/p5.sound.min.js"></script>
<script src="/hypercollective/libraries/addons/p5.clickable.js"></script>
<script src="/hypercollective/libraries/socket.io-stream.js"></script>
<!-- THIS DOESN"T WORK -->
<!-- <script src="/socket.io/socket.io.js"></script> -->
<!--ONLY WORKS WITH CDN-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="joinStyle.css">
<meta charset="utf-8" />
</head>
<body>
<script src="joinBackgroundObj.js"></script>
<script src="joinSketch.js"></script>
<!-- [START cloudrun_websockets_client] -->
<!-- <script src="socket.io/socket.io.js"></script> -->
<!-- [END cloudrun_websockets_client] -->
</body>
<!-- <script src="/socket.io/socket.io.js"></script> -->
</html>
```
my main directory app.js :
```
const hls = require("hls-server");
var fs = require("fs");
var express = require("express");
//var tools = require("./extras/textGen.js");
const ffmpeg = require ("fluent-ffmpeg");
var https = require('https');
var app = express();
app.use('/hypercollective', express.static("public"))
var server = https.createServer(app);
server.listen(8080);
var io = require('socket.io')(server);
const sampleRate = 44100;
var flag = 0, refreshing = 0; //flag if have received some audio for refreshing
var canvasSize = 60*5; //in seconds
// THESE BELOW (app.get) DO NOTHING! NOT SURE WHY
// app.get("/", (req, res) => {
// return res.status(200).sendFile(`${__dirname}/public/index.html`);
// });
// app.get("/join", (req, res) => {
// return res.status(200).sendFile(`${__dirname}/public/join/index.html`);
// });
io.sockets.on("connection", newConnection);
function newConnection(socket) {
socket.on("connectedforrecording", () => {
// console.log("anything")
}
```
my public/bar/joinSketch.js:
```
const socket = io("", {
transports: ["websocket"],
});
socket.emit("connectedforrecording");
// other bits not added
```
I have gotten a slew of errors, most recently:
'wss://mydomain.com/socket.io/?EIO=4&transport=websocket' failed: and when i don't force websockets, I get a 404 on transport=polling...
express
socket.io
google-cloud-run
0 Answers
Your Answer