-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force https in production (deployment) #1409
Comments
It's pretty unrelated. That's config on the server, not the running code. If you don't want your code to work in non https you could check that the url starts with |
Create React App doesn't handle the server in production. It generates a static file structure that can be served by anything.
Edit: It seems I would recommend writing a really simple |
I haven't tested this, but if configuring the server to do this isn't an option, you may try something like this (in your index.js; first line(s) of the file): if (window.location.protocol !== 'https:') {
window.location = 'https:' + window.location.href.substring(window.location.protocol.length)
return // to stop app from mounting
} This, however, defeats the purpose of preventing against a MITM attack if a malicious entity wanted to disguise your website as a whole. I wouldn't use it if I were you. |
@Timer That defeats the purpose of HTTPS enforcement, as the entire package (including the javascript) will be delivered over tamperable HTTP. Also, if the server isn't configured to serve over https then it will redirect to an url that won't connect as the server isn't listening on 443. This is something that has to be solved at the server level (and thus not a CRA concern), the server should enforce the transition to prevent the client from receiving the app over http. |
I'm aware of those implications @Reanmachine (and I would never do it that way, personally), but I was just offering the option. |
Sorry @Timer I must have missed that when reading your response. |
Thanks guys, I will set it up on the express server. |
@Reanmachine Using https-pushstate-server instead might be the solution |
Is there a way to force the app to use https ?
The text was updated successfully, but these errors were encountered: