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

279
Vistas
Node Express Frontend and Backend-Route on same url path

I'm building an URL shortener with NodeJS and Express in the Backend and Angular in the Frontend, which is deployed in a single docker container. The most important feature (redirect from short URL to long URL) should be handled on the base path of the backend. In the best case, I also would like to provide the frontend on the same route.

This is a high level overview of my backend:

import express          = require("express");
const app = express();
...
app.get('/*', isOnline, express.static(path.join('./', 'frontend'), { maxAge: '1y' }));

app.use('/', redirectRoutes);

app.listen(port, () => console.log('API running on port ' + port));

The frontend folder contains the built Angular application (most important an index.html). I don't understand, why it is not working. As far as I understood, the frontend should be delivered if any route matches a file within the frontend folder (index.html).

If not the redirectRoutes should take action.

But every time I open a redirect route (e.g. example.com/abcdefgh), I the frontend will displayed, which don't have any route abcdefgh.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think the first app.get('/*' is taking precedence for every route from the root e.g. /

Usually the API routes would begin app.use('/api' for this reason

The order is important, so you'd put the api one first

over 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