1

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...

Teoman Kirac
  • 748
  • 3
  • 8
  • 16
  • 2
    Where is the `/index.html` coming from in the browser. How do you load and display that page from the browser? I note that your server is running on port 8080, but the socket.io error you get shows `wss://mydomain.com/socket.io/?EIO=4&transport=websocket` which does not indicate port 8080. – jfriend00 Apr 07 '22 at 01:12
  • Can you also provide your Cloud Run logs? – Robert G Apr 07 '22 at 08:07
  • /index.html is "public/bar/index.html is:"... i "gcloud run deploy" my project from the main directory and within this main directory there is the public folder. – Teoman Kirac Apr 07 '22 at 08:26
  • Operation completed over 1 objects/1.1 MiB. BUILD Pulling image: gcr.io/k8s-skaffold/pack Using default tag: latest latest: Pulling from k8s-skaffold/pack Digest: sha256:410a0f8a63d42b0c5ac800ba9c71789fcbffbf4fc4691a109e2883e3a365b629 Status: Downloaded newer image for gcr.io/k8s-skaffold/pack:latest gcr.io/k8s-skaffold/pack:latest latest: Pulling from buildpacks/builder – Teoman Kirac Apr 07 '22 at 08:35
  • i get 503 404 on mydomain.com/foo after the effects or removing foo/bar/* on load balancer paths hit the browser.. – Teoman Kirac Apr 07 '22 at 08:39
  • @jfriend00 mydomain.com runs on port 443. mydomain.com/foo is the cloud run container and runs on 8080. mydomain.com/foo/bar, where bar is the path of the container, also runs on port 8080, and this is where i need to get socket.io to load proper.... – Teoman Kirac Apr 07 '22 at 09:14
  • @jfriend00 would i need to set up two different load balancers actually? i just assume the cloud run container takes over once in its path.. mydomain.com/foo – Teoman Kirac Apr 07 '22 at 09:19
  • @jfriend00 please see this question: https://stackoverflow.com/questions/71782111/can-i-use-one-google-cloud-load-balancer-for-a-static-backend-bucket-and-a-conta – Teoman Kirac Apr 07 '22 at 12:31

0 Answers0