Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

319
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda