Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
express vhost doesn't proxy the cdn in localhost

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:

http://cdn.somedomain.com.local:3000/

Target resource should be something like this:

https://cdn.somedomain.com/

I have been trying a couple of other options, none of them seems to work as expected.

Appreciate any help in this matter!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!