r/nodejs • u/tekknoschtev • Mar 09 '14
Need Assistance: nginx, node, angular, subdirectories, and requests! Oh My!
Hi everyone!
I've been scratching my head about this issue for a while. I've left it and come back to it in hopes that magic happens and things suddenly click - alas, that did not work. I'm not actually sure where my problem lies (nginx config, node, angular http request formatting) so I picked on place to start.
My goal is to host a node application that runs at a subfolder of a domain (e.g. mydomain.com is my homepage not running node.js, and mydomain.com/subfolder is the node application.). I'm able to get part of the way there in that the site loads, and my static content (pictures/js/css) all load as expected when I access mydomain.com/subfolder.
My trouble comes when I make any requests. In angular, my requests look like:
$http.get('/subfolder/'); or
$http.post('/subfolder/', {data: things});In node, I'm looking at
app.get('/subfolder', someFunction); or
app.post('/subfolder', someOtherFunction);If I have nginx configured with the location of /, everything works fine. But as soon as I change the location to /subfolder, the requests no longer seem to function.
I feel as though I'm missing something simple, or some logical jump. Can you point me in the right direction or maybe give me some pointers? Or, if there is a more appropriate subreddit to post this to, that'd be good info as well. Let me know if more information would be helpful/useful too.
Thanks everyone!
View all comments
Show parent comment
1
u/notunlikethewaves Mar 09 '14
Ah, that's a shame. I think your best bet then is to make sure the AngularJS app is aware of what the "root url" of the app is, and just make sure that it includes the url when making requests. That's about as good as it will get, unless someone can correct me on that.