Route issue in Node JS with express - node.js

I have a godaddy domain being redirected to an instance of EC2 with an elastic IP. on instance there runs my NodeJS on port 5000. i m redirecting 80 to 5000( till here everything works fine). In express i have a route say '/Calculate/:Type', which is visited when some caculate button is pressed. ideally the when button is pressed a request to server should go like http://example.com/calculate/3 but here is goes http://example.com//calculate/3 an extra / before caculate ruins the entire route. can someone please tell me why is it happening?

Modify the route where you define the findone query and remove the forward slash from it.

Try adding a period in front of /Calculate/:Type so
'./Calculate/:Type' in your express route
Ahh so it seems like you may be hitting a CORS error. Is your webserver and dataserver on the same url?
Best option : Put the node instance serving your app on yourdomain.com, and make your api endpoint api.yourdomain.com/Calculate/:Type
Other Option: exposing yourself to security risks by adding a 'Access-Control-Allow-Origin = *' in the header of your response
Other Option: expose yourself to security change your settings in htaccess to allow all, or the specific domain

Related

NodeJS redirect to internal localhost server

I am new to nodejs so apologies if this is a bad question.
I am using NodeJS + Auth0 to authenticate a shiny webapp. I have most of it working now including the call back but am stuck on the last step.
Assuming it authenticates, I want to proxy pass directly to 127.0.0.1:3838/myapp.
In other words, if the loopback address were public I could do:
res.redirect('http://127.0.0.1:3838/myapp/');
However, as it's not public that is no longer an option. Any advice?
res.redirect('/myapp'):
Should redirect you to the /myapp route assuming that you are running the NodeJS app locally on 127.0.0.1:3838
Have a look at https://stackoverflow.com/a/44445540/16471349

Apache & NodeJS Express = how use same 404 page

I'm using proxy on Apache to proxypass subfolder of domain to Node.js Express app on local port, but is there a way from Express side, somehow to pass purely a status in a way, so Apache uses own error page? (I want them to look the same).
As far as I know I may either use absolute path on server to that page etc, but that may not be consistent if I change the Apache settings. Is there any way to tell Apache over proxy request response, to show his error page, whatever it has been set to?
Maybe there is no such way, I just wonder if there is some way. The best I came up so far is to redirect to same URL but starting with /e/ which would work, but remains /e/ in URL - not bad, but maybe someone give a better hint.

Detect if user uses proxypass in Apache or NodeJS

I have developed a NodeJS app running on port 1234. In order not to have ":1234" in the address bar, I use proxypass/proxypassreverse so that the URLs look like "mysite.com/myapp/".
Everything works fine but my app is behind a SSO. When a user tries to reach "mysite.com/myapp", he's redirected to the SSO, he logs in, then the SSO redirects him to "mysite.com:1234" (because the SSO doesn't understand that there is a proxypass).
I created a javascript on my page detecting if there is ":1234" in the URL and if so, the window.location replaces ":1234" by "/myapp".
This is not a very good solution for me, I think there may be a NodeJS or even better an Apache solution to detect if the URL reached is the ":1234" one or the "/myapp" one.
Thanks in advance.
OK my problem was that NodeJS sent to the SSO the URL with the port number. All I needed to do was to replace the port number by the string I use for the ProxyPass:
req.get('host').replace(':' + PORT, '/node')

Sails.js res.redirect() don't support proxyHost

I have config
proxyHost: 'http://localhost:1337/1.0',
and routes
'GET /1.0/subscriptions/success': 'SubscriptionController.success',
In controller,
res.redirect('/subscriptions/success');
Browser is redirect to URL "http://localhost:1337/subscriptions/success", I expect it will redirect to "http://localhost:1337/1.0/subscriptions/success".
Where can I make config to this?
You're misunderstanding what the proxyHost setting is for. It is solely to allow sails.getBaseurl() to return the correct base URL for when your site is being proxied (e.g. by Nginx) so that the public-facing host/port is different from the host/port exposed on the server. It doesn't affect the URLs of the routes that are bound in your app, nor does it affect the action of res.redirect.
If you want to prefix all of your routes with /1.0, you can use the prefix setting in config/blueprints (documented here). You'll still need to include the prefix manually when doing redirects, but you won't need to actually nest your controllers under a /1.0 folder.

IIS Express SSL Request Redirection Issue

I have a port conflict issue. I need my IISExpress to be able to cater these web request:
http:// localhost:44567/
and
https:// localhost:44567/
I know these are conflicting ports since SSL connection should have its own port.
I am also aware that we can solve this from the client side by changing requesting link to a different port.
But what I am looking is, if there is a way from the server side(IISExpress) to resolve this problem. Like for example:
If IISExpress receives http:// localhost:44567/ then it will serve it as it is. And if it receives a request for(SSL) https:// localhost:44567/ it will redirect it to a different port, let us say to https:// localhost:44569/. Or maybe changing https:// to http://?
Is there a way to do this in IISExpress?
Or is there another approach to this problem?
NOTE: I need a solution for the server side and not from the client side. Thank you.
NOTE: I intentionally put space in the domain name because I am not allowed to put links in the question.

Resources