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

91
Vistas
express methods having strange behaviors

i have routes with the get method.

app.get("/info/teachers", controller1);

app.get("/info/teachers/:teacherid", controller2);
app.get("/info/students", controller3);
app.get("/info/students/:studentid", controller4);
app.get("/info/courses", controller5);
app.get("/info/courses/:courseid", controller6);

app.get("/info/courses/enrolled/:studentid", controller7);
app.get("/info/assists/teachers", controller8);
app.get("/info/assists/teachers/:teacherid", controller9);
app.get("/info/courses/:teacherid", controller10);

app.get("/info/assists/students", controller11);
app.get("/info/assists/students/:studentid", controller12);

all of them works except for app.get("/info/courses/:teacherid", controller10);

but if i move his position to:

app.get("/info/teachers", controller1);
app.get("/info/courses/:teacherid", controller10);

app.get("/info/teachers/:teacherid", controller2);
app.get("/info/students", controller3);
app.get("/info/students/:studentid", controller4);
app.get("/info/courses", controller5);
app.get("/info/courses/:courseid", controller6);

app.get("/info/courses/enrolled/:studentid", controller7);
app.get("/info/assists/teachers", controller8);
app.get("/info/assists/teachers/:teacherid", controller9);
app.get("/info/assists/students", controller11);
app.get("/info/assists/students/:studentid", controller12);

it just works; why is this happening? all the controllers works independtly and dont need information from the others.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There's no distinction between /info/courses/:teacherid and /info/courses/:courseid. The router will pick the first that matches, and they both match the same urls.

In your second snippet, controller6 will never be called.

You'll either need to change that route to something like /info/courses/taught/:teacherid (like you did with /enrolled), or you'll need to have a single route /info/courses/:someId with a controller that can distinguish whether someId is a teacher id or a course id. (Different prefixes, maybe?)

about 4 years ago · Juan Pablo Isaza 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