I've rented a dedicated server, set up a website (somedomainblah.com), and on the subdomain (app.somedomainblah.com), I have a node.js app that requests an image from the website (my website is on that server).
So the dedicated server itself is at IP: 0.0.0.210 And my cPanel account which I created on the dedicated server is at 0.0.0.211 (where website is located)
I got the error:
RequestError: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: myrootdomain.com. is not in the cert's altnames: DNS:0-0-0-210.cprapid.com, DNS:mail.0-0-0-210.cprapid.com, DNS:www.0-0-0-210.cprapid.com
I tried rejectUnauthozized false, and it give me error 404.
Here is the code of Node.js app:
const express = require('express');
const cors = require('cors');
const request = require('request');
const fs = require('fs');
const app = express();
app.use(cors());
const rp = require('request-promise');
app.get('/images/:imageId', async (req, res) => {
// Set the necessary headers for CORS
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT');
res.setHeader(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
);
// Get the image from another source
const imageId = req.params.imageId;
const imageUrl = 'https://somedomainblah.com/play/images/' + imageId +'.png';
try {
const image = await rp({
method: 'GET',
uri: imageUrl,
encoding: null,
});
res.set('Content-Type', 'image/png');
res.send(Buffer.from(image, 'binary'));
} catch (error) {
console.log(error);
return res.status(500).send('Error retrieving image');
}
});
app.listen(3000, () => {
console.log('Server started on port 3000');
});