So I'm trying to create a script in Tampermonkey (JavaScript) to send data to a node.js server. For those who don't know what Tampermonkey is, it's basically an extension to run JavaScript scripts on websites to add stuff (ex make an overlay on a .io game). However, along with this I'm trying to send the data from the node.js server to another client on a different computer (not the problem). My problem arises when I stop hosting the node.js server on localhost and instead on the computer's address (so it can communicate with client on computer #2) Here is my code for the server
const app = require('express')();
const https = require('https');
const fs = require('fs');
const httpsServer = https.createServer({
key: fs.readFileSync('./server.key'),
cert: fs.readFileSync('./server.crt')
});
const port = 4000;
httpsServer.listen(port, "192.168.1.38", function () {
console.log('LISTENING');
});
const ioServer = require( "socket.io" );
const io = new ioServer();
io.attach( httpsServer );
io.on( "connection", function( socket ) {
console.log('client connected');
});
The code for the Tampermonkey client is:
// ==UserScript==
// @name testscript
// @namespace http://tampermonkey.net/
// @version 1
// @description try to take over the world!
// @author user12751150
// @match *://diep.io/#*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.min.js
// ==/UserScript==
var socket = io.connect('https://192.168.1.38:4000');;
function socketThing() {
socket.emit('test', {"test": "data"});
}
setInterval(socketThing, 500);
(it's just a test script, so it doesn't actually do anything useful)
Whenever the script is running it shows this in console:
GET https://192.168.1.38:4000/socket.io/?EIO=3&transport=polling&t=M_5NBeo net::ERR_CERT_COMMON_NAME_INVALID
I have tried many solutions, such as How can I create a self-signed cert for localhost? and How to generate a self-signed SSL certificate using OpenSSL? and many others, but they don't work. I'm not sure if I should make a self signed certificate for localhost and then just change it to my computer's IP, or if I have to create something completely different.
I have currently tried:
- creating a certificate with common name as 192.168.1.38
- creating a certificate with everything as 192.168.1.38
- creating a certificate with 192.168.1.38 and https://192.168.1.38 as alternate IPs