How to stop localhost http://localhost from switching to https://localhost - ruby-on-rails

I am writing a web application, and http://localhost:3000 is redirecting to https://localhost:3000
This was not happening a month ago when I finished writing two other applications. I went from working with Sinatra to Rails in the past month, although I have worked with Rails prior without any of these issues.
What can I do to stop this forced switching??

This is probably due your browser, because you have accessed the app in the HTTPS address, it will automatically switch to the HTTPS version of site.
Here you have more information for Firefox, but the solution is to change the settings and set browser.urlbar.autoFill to false. Other option could be to clear the History.

Related

Next.js website works under IP address, but not under domain

So I am really desperate right now. It is new year's eve and I don't want to deal with this stuff anymore, but I don't want to slide into 2023 with a broken web app.
Yesterday, suddenly out of nowhere my Next.js production website stopped working properly. The project works well on my localhost, no issues. Also it works fine on my server (if I access the website via IP_ADRESS:3000). But when I use the production URL, the website opens and looks fine but I cannot interact with it, nothing is clickable, nothing reacts, the links do not work, the inputs are broken.
I'm hosting it on a Ubuntu & Nginx DigitalOcean droplet, with Node & Next.js - also I use Cloudflare (and I think it has something to do with that, since with the bare IP address the website works fine).
I tried a lot of things, put it onto a new server, reinstalled Nginx, reinstalled the SSL certificate, rebuild the production build etc, but it still does not work, when I access it through the website url, so the issue must be with that. Though I am really frustrated right now and I don't know what might be causing this.

Rails server gets response, but localhost page hangs randomly until system reboot

I'm working on a project with a Rails 6.0 backend using webpacker with a React frontend. While working on the frontend with the rails server, my app will sometimes break on Google Chrome, endlessly loading but never even showing the new page title on the tab.
The rails server is receiving the request. It will hit debuggers in the backend and it returns with a 200 status code, but Chrome refuses to load the page while giving no errors or messages indicating what is wrong. This persists even after I restart the rails server, if I restart it on a different port, and if I restart the webpack dev server. I've tried clearing my cache and disabling the cache with devtools, but the only thing that fixes it is rebooting my entire system.
It seems to happen randomly, though I think it may be happening if I refresh the page out of the chrome debugger. I am using ajax for calls to my backend API, not sure if that's possibly a factor.
I've never had this problem before and I'm unsure what it even possibly could be. Does anyone have any idea what might be happening here?

MVC WebApplication no longer starts in IIS Express (redirects to https://localhost in Chrome)

I was changing OAuth/Owin settings and Azure publish settings in a Web Application project this morning, but soon after we decided deployment will be to a specific IIS Azure VM (now visible across our local domain). All code/setting changes have been reverted.
At one point I also changed the drivers\etc\hosts file to allow a dummy name for Microsoft OAuth, but that has been reverted.
Notes:
My startup URL is http://localhost:22222/
I am running under IIS Express (as my local Dev VM will not allow me to install full IIS)
When I start the Web Application with IE I simply get "This page can't be displayed"
If I start it with Chrome I get "This webpage is not available", but it also changes the browser URL to https://localhost (note the s, i.e. using SSL).
I have pulled the project down fresh from source control. No change.
The project is under TFS source control.
Another developer on the same project has the latest files and it works fine.
If I run any other Web Application project, they work just fine.
All OWIN registration of providers has been commented out. No change.
Deleted the entire project folder and pulled fresh from TFS. No change. This probably means a local machine setting somewhere is the cause?
What could I have damaged in my Web Application to cause this problem? I have been scratching my head for hours now and nothing we try is working. The application simply will not start in any browser.
Project Web Settings tab:
Answer at bottom, given to this chromium issue [issue 444479] helped me:
Same here - I also believe caused by HSTS - see
http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
If you have (developed) any other localhost sites which send a HSTS
header...
eg. Strict-Transport-Security: max-age=31536000; includeSubDomains;
preload
...then depending on the value of max-age, future requests to
localhost will be required to be served over HTTPS.
To get around this, I did the following.
In the Chrome address bar type "chrome://net-internals/#hsts"
At the very bottom of a page is QUERY domain textbox - verify that localhost is known to the browser
If it is, DELETE the localhost domain using the textbox above
Your site should now work using plain old HTTP
HTH,
Jay
ps. This is not a permanent solution, but will at least get it working
between projects. If anyone knows how to permanently exclude localhost
from the HSTS list please let me know :)
Give it a try.

Rails 4 favicon in localhost

I created a favicon for a rails app I've built a month ago. Now I'm working on a new app without a particular favicon, yet every time I go to localhost:3000 the old favicon appears. I know it really doesn't matter and it won't appear in production but it bugs me. Can anyone explain why it keeps showing and how can I remove it?
Thanks.
The reason is simple, the browser is being smart and caches the favicon as it associates it with the URL, i.e. http://localhost:3000.
To test it in Chrome, just open http://localhost:3000 in an incognito window (CTRL+SHIFT+N) and you will not see the favicon there.
To remove the favicon, simply clear the browser cache.
It appears in development on localhost:3000 because it got cached.if run your server on different port like 4000(rails s -p 4000) and access localhost:4000 then it won't show you the old favicon.

Session errors when accessing a development Rails app through VirtualBox

I'm developing a Rails 3 app on Ubuntu 10.10 and need to check the CSS and Javascript on IE7 and IE8, so I'm using VirtualBox and the images that Microsoft provides. I've gotten the images installed and running well - I can use IE7 and IE8 to access the internet and use sites just fine.
I can also access my development Rails app (running on Ubuntu) by visiting 10.0.2.2:3000 in each browser (not sure why that works and localhost doesn't, but oh well). Any GET on a page that doesn't require the user to be logged in renders as I'd expect it to.
What's wrong are the sessions - as near as I can tell, both IE7 and IE8 are both just completely ignoring sessions with the development app. Whenever I submit the login form I get an InvalidAuthenticityToken error, and sure enough, in Rails' error page, the values in the session and params don't match. I even set up a special route to automatically log in the visitor as a random user, but it doesn't work. I just downloaded and installed Firefox in one of the virtual PCs and it's having the same problem as the IEs are.
Everything works perfectly in Chrome/Firefox in Ubuntu, so it doesn't seem to be Rails, and apparently it's not IE. I suppose there's something I'm missing with VirtualBox, but I have zero experience with virtualization before today, so I don't even know how to begin troubleshooting it.
Any advice?
Figured it out: The cookie wasn't being set because I was visiting the app through the ip address (Rails' :domain => :all option for the cookie store apparently doesn't cover that eventuality). I pointed lvh.me to 10.0.2.2 in the hosts file in WinXP, and everything works great.
I just had a similar problem on IE8, session cookies were turned off. My Rails app login worked after I turned session cookies to on via:
Internet Explorer > Tools > Internet Options > Privacy tab > Advanced button > tick "Always allow session cookies"

Resources