I have a node.js backend with an express server. I would like to default all get requests to the angular app and use the angular routing to handle the requests. The express server would handle all of the api calls from the angular app. I have set up my express routes with all api calls at the top and the following code at the bottom:
app.get('*', function(req, res){
res.sendfile('index.html', { root: path.resolve(__dirname + '/../../app') });
});
This works great for the default home page but it does not work well if there is a faux folder. E.g.
www.example.com (works)
www.example.com/product1 (works)
www.example.com/products/1 (does not work)
My HTML file references scripts using the following structure:
<script src="scripts/app.js"></script>
When I try to access a url with a faux folder (www.example.com/products/1) I get the following error: Cannot find file ‘products/scripts/app.js’
It is trying to use the folder in the url to find the file. Is there a way to resolve this? Or should I use express for the routing instead of angular?