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.
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