I have a very strange problem.
I am using NodeJS with ExpressJS. I have also enabled "passport" module to authenticate the user.
I have the following route
app.get("/home", ensureLoggedIn("/login"), (req, res) ->
    res.render "home",
        title:"Home"
)   
Which works fine after user logs in for the first time.
Now when I am in "localhost:3000/home" and I refresh, the it seems like not all the CSS and JS files are being loaded, so my Chrome just keeps "loading" (the spinning image).
When I look at my console, I've got the following logs being printed out
GET /home 200 14ms - 1.32kb <-- first time page being loaded...
GET /css/main.css 304 19ms
GET /js/libs/handlebars.min.js 304 12ms
GET /js/libs/underscore-min.js 304 19ms
GET /js/libs/jquery-ui-1.10.2.custom.min.js 304 21ms
GET /js/libs/jquery-migrate-1.1.1.min.js 304 26ms
GET /js/libs/backbone-min.js 304 19ms
GET /js/libs/jquery-1.9.1.min.js 304 31ms
GET /home 304 18ms <-- second time page being loaded
GET /js/libs/underscore-min.js 304 14ms
GET /js/libs/jquery-ui-1.10.2.custom.min.js 304 16ms
GET /js/libs/jquery-1.9.1.min.js 304 15ms
GET /js/libs/jquery-migrate-1.1.1.min.js 304 15ms
At first it seemed like it was a particular JS file, so I took the "jquery-migrate-1.1.1.min.js" file out, but it happens again on another JS file I trying to load.
I thought it was something to do with the "passport" module, so I took the "ensureLoggedIn" code OUT but it's still happening.
Any ideas?
Once the browser "hangs" and doesn't load anything, I can't go anywhere. I type in any URL in the browser to get the any of the assets (e.g. CSS files, JS files, images) or paths, the it just keeps loading and there is nothing in the console log.
This is getting more strange. So here's what I did. When I go to a route
app.get("/home", (req, res) ->
    res.render "home",
        title:"Home"
)
With my (very simple) home.jade file
!!! 5
html(lang='en')
head
  body
Everything works fine. I can refresh the page many multiple times and there's no problem.
Then I enable "passport" module and go to
app.get("/home", ensureLoggedIn("/login"), (req, res) ->
    res.render "home",
        title:"Home"
)   
I can login successfully and my "home" (home.jade) file displays correctly. And here's the kicker. I refresh exactly 16 times and then on the 17th time, the page hangs.
I stop my NodeJS server and restart and the exactly the same thing, works up to 16 refreshes and on the 17th, it stops.
I feel like there is a some sort of "request" limit in passport module? Or I just might be going crazy.
I've found my problem - a rookie mistake - I was using Postgres as my DB and for each query, I wasn't "closing" the connection properly. So each time I refreshed, it opened a new connection to the DB - silly, silly.