I was trying to proxy a cdn url (https://cdn.somedomain.com/) in localhost using vhost middleware but it gives me some strange error.
Before going into the issue, I have been trying to access a cdn url which produces a CORS error where the resource doesn't allow wildcard (*), I need to match the domain name to fix that. So, I tried aliasing the domain name to the local IP address in /etc/hosts/.
Something like this:
127.0.0.1 cdn.somedomain.com.local
Here is my server configuration file:
const express = require('express');
const vhost = require('vhost');
...
const app = express();
const { cdn } = require('./cdn.js');
app.use(vhost('cdn.somedomain.com.local', cdn));
The last line complains about a compilation error:
No overload matches this call.
The last overload gave the following error. Argument of type 'Function' is not assignable to parameter of type 'PathParams'. Type 'Function' is missing the following properties from type '(string | RegExp)[]': pop, push, concat, join, and 27 more.
cdn.js
const express = require('express');
const cors = require('cors');
const path = require('path');
const cdn = express();
cdn.use(cors());
cdn.use(express.static(path.resolve(__dirname, '../static-host/')));
module.exports = { cdn };
When I run the app, I get a 404 and the request url looks something like this:
Target resource should be something like this:
I have been trying a couple of other options, none of them seems to work as expected.
Appreciate any help in this matter!