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

278
Views
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 answers
Answer question

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 Report
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!