Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
Issue with express static middleware and subdirectory

I have this folder as my website structure

-views
  -index
  -post
-public
  -css
  -js
  -images
-app.js

But a post link can be:

mywebsite.com/posts/a-link-example

So, when I use express static middleware like this:

app.use(express.static(__dirname + '/public'));

it only works in pages without a "subdirectory" like

example.com/home
example.com/contact

but not on

example.com/posts/post-name

I can use of course:

app.use('/posts, express.static(__dirname + '/public'));

but is there a better way to do it?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Don't use relative paths to point to static resources (like scripts and stylesheets), use absolute paths:

<link rel="stylesheet" href="/css/style.css">
about 4 years ago · Santiago Trujillo Denunciar

0

You can change static asset links from:

<link rel="stylesheet" href="./css/style.css">

to:

<link rel="stylesheet" href="/css/style.css">
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda