So I want to set up a basic node server to work with my clientside Angular application. My folder structure looks like this:
.tmp //Contains css stylesheet
bower //Obviously contains bower packages
public //Contains client code
This is what my index.html looks like (at least, the scripts/stylesheets)
 <!-- bower:css -->
  <link rel="stylesheet" href="bower/bootstrap/dist/css/bootstrap.css" />
  <!-- endbower -->
  <!-- inject:css -->
  <link rel="stylesheet" href="/.tmp/styles.css">
  <!-- endinject -->
<!-- bower:js -->
<script src="bower/jquery/dist/jquery.js"></script>
<script src="bower/angular/angular.js"></script>
<script src="bower/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower/angular-route/angular-route.js"></script>
<script src="bower/angular-resource/angular-resource.js"></script>
<!-- endbower -->
<!-- inject:js -->
<script src="/public/app/modules/sportStore.module.js"></script>
<script src="/public/app/controllers/checkout.controller.js"></script>
<script src="/public/app/controllers/productList.controller.js"></script>
<script src="/public/app/controllers/sportsStore.controller.js"></script>
<script src="/public/app/filters/customFilters.js"></script>
<script src="/public/app/components/cart/cart.js"></script>
<!-- endinject -->
And this is my middleware configuration in my server.js file:
app.use(logger()); //require('morgan')
app.use(express.static('./'));
app.use(express.static('./public/'));
app.use(express.static('./tmp/'));
app.use('/*', express.static('./public/index.html'));
What I understand this does is that: for every request:
- Log it
 - See if you can find the file request under ./
 - If it's not there, looks under ./public/
 - If it's not there, look under ./tmp/
 - If it's not there and the request contains something after the '/' serve index.html
 
How I'm going to handle client-side routing (with Angular's $routeProvider) is not clear to me yet, perhaps I won't even need to do that, I'm not sure if those requests will go to the server.
However doing all of this results in an infinite loop and I honestly have no idea why. I thought I understood middleware but obviously there's something wrong with my logic, or this would be working.
So basically my 2 questions are:
- Is what I summed up how express' middleware works?
 - If it's not, perhaps you could give me a push in the right direction?
 
Don't just point me to express' docs, I've read them over like 5 times but I find that the documentation doesn't explain it clearly enough.