1

I have a virtual machine (VM) running with Google Compute Engine. This website is hosting a Node.JS website using Socket.io. When I connect directly to the website using its IP, it works fine. I then used Google's built-in Cloud DNS to make a zone and connect my VM to my domain.

I assigned my nameservers via my registrar NameCheap and assigned my static VM IP to the zone. I tried to connect to my domain name, but I get the error "Received invalid response". I suspect this is an issue with the port number (80) I'm using, so I change it to port 443, and still nothing.

I suspect this is due to an SSL certificate not being issued to my domain, which I assumed Google would do on my behalf. How should I proceed to fix this bug? I heard about Nginx and Certbot being able to issue SSL certificates, but after 6 hours of having difficulty with them working, I didn't work with them further.

This is the stage I'm currently at, please let me know of anything that could possibly be the issue, and ask for files and more details if needed. I'll attach some relevant files to my project.

server.js

const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
const fs = require("fs");

async function getCount() {
    return new Promise((resolve, reject) => {
        fs.readFile("count.json", (err, data) => {
        if (err) {
            reject(err);
        } else {
            const count = JSON.parse(data).count;
            resolve(count);
        }
        });
    });
}

async function writeCount(count) {
    const data = {
        count: count
    };

    return new Promise((resolve, reject) => {
        fs.writeFile("count.json", JSON.stringify(data), (err) => {
        if (err) {
            reject(err);
        } else {
            resolve();
        }
        });
    });
}


app.use(express.static("public"));
app.use((req, res, next) => {
    res.set('Cache-Control', 'no-store')
    next()
})

io.on("connection", (socket) => {
    socket.on("error", console.error);

    getCount().then(count => {
        io.emit("init", count);
    }).catch(err => {
        console.log(err);
    })

    socket.on("serversync", (receivedSync) => {
        console.log("received " + receivedSync);
        if (receivedSync >= 120) {
            console.log("not using " + receivedSync);
            return;
        }
        
        getCount().then(count => {
            let total = count + parseInt(receivedSync);
            io.emit("clientsync", total);
            writeCount(total);
        }).catch(err => {
            console.log(err);
        })
    });
});

app.get("/init", (req, res) => {
    let files = fs.readdirSync("./public/audio");
    res.json([files]);
})

const PORT = process.env.PORT || 8080;

server.listen(PORT, () => {
    console.log(`Listening on port ${PORT}.`);
});

app.yaml

runtime: nodejs
env: flex

manual_scaling:
  instances: 1

handlers:
 - url: /
   static_files: public/index.html
   upload: public/index.html

network:
  session_affinity: true
  forwarded_ports:
    - 65080/tcp
LazyBeast
  • 45
  • 4
  • If you are going to use Google Cloud DNS to host your DNS records, then you must point your domain registar's NS Records to your Google Cloud DNS zone's NS Records. But if you want to use Namecheap's Name Servers, just simply manage your DNS records through Namecheap and delete the Cloud DNS zone. You can't manage your DNS records through Google Cloud DNS while using Namecheap's name servers. – James S Mar 14 '23 at 00:01
  • @JamesS I did configure them like that, that's not what ended up being the problem. My server is receiving requests but they're not valid. – LazyBeast Mar 14 '23 at 10:46

1 Answers1

1

I ended up finding the problem myself, it was an issue with the SSL certificate. I spent some more time on Nginx and Certbot until I hit a roadblock where my domain wouldn't verify. The problem ended up being that my DNS configuration didn't have a CNAME record pointing the www version of my domain to the normal one, after that the domain was registered successfully and the site was working perfectly.

LazyBeast
  • 45
  • 4