baryshev / connect-domain

MIT License
85 stars 11 forks source link

Requests for static files hanging when using connect-domain before express.static middleware #12

Closed renatoargh closed 8 years ago

renatoargh commented 11 years ago

Hi guys, this is not exatcly an issue (but a misuse maybe), so I am creating this issue to keep documented so other folks may not struggle and get stucked like me.

Requests like myapp.com/js/jquery.js were simply hanging forever in the server not allowing my page to be fully rendered, was not even getting error 404. And the most crazy part was that sometimes it worked sometimes not. At a totally random fashion.

My code before (with problems):

app.use(connectDomain());
app.use(express.compress());
app.use(express.static(__dirname + "/static"));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());

Then I solved by pulling connectDomain some lines down the stack:

app.use(express.compress());
app.use(express.static(__dirname + "/static"));
app.use(connectDomain());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());

Maybe its worth adding this info at the readme file.

rprieto commented 11 years ago

Wow, thanks! Took us forever to figure out the source of the problem - and we ended up removing connectDomain() altogether. Definitely worth fixing / mentioning in the README.

In our case, we could load views & assets once, but every request after that first page would just hang there.

jpillora commented 11 years ago

:+1: glad I checked the issues first!

sebz commented 11 years ago

Thank you so much ! In my case, calls to an external API was only working once. To solve the issue I had to move it after app.use(app.router) just before my route declarations.

PaquitoSoft commented 10 years ago

Thank you all for this info. It's really helpful. I also agree the README file should be updated to mention this.

sebastien-mignot commented 10 years ago

Same bug for me, and it wasn't static files, it was standard routes. When I moved connectDomain after app.use(app.router) like sebz, it worked. Seems like a bug to me ! (moreover since connect-domain is there to catch the errors thrown during the router work, it more natural to put it before it ; even if this won't change anything since the asynchronous errors will be thrown later anyway)

sebastien-mignot commented 10 years ago

I stand corrected, the bug is fixed by putting connectDomain after app.use(app.router), but now asynch errors are not caught anymore.

If I can't fix this bug, i'll have to remove connect-domain...

The requests that don't answer are the PUT requests. The GET work correctly.

deyhle commented 10 years ago

+1

Some requests sometimes (not every time) just fail. Removing connectDomain fixes it…

sebastien-mignot commented 10 years ago

Any news on this issue dear developers ? I'm not using connectDomain because of this, it seems like a shame.

chichilatte commented 9 years ago

I had similar problems, and after a few hours I gave up trying to diagnose it. In the end I used another (more popular) module called express-domain-middleware. Works for me :)

Still appreciate baryshev's work, despite the probs.

sebastien-mignot commented 8 years ago

@renatoargh Why did you close this ? connect-domain is unusable for us because of this bug (or the related one with standard routes)

renatoargh commented 8 years ago

I closed this by inactivity (not being closed by the developers) - and also because it was polluting my issues feed. I think it is more appropriate to open a new one and reference it here if it still applies to you!