remix-serve should redirect HTTP traffic to HTTPS #2915
Replies: 3 comments 1 reply
-
Agree, this is something the server should do, not the app |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I was looking to add HTTPS support in my Remix App Server The recommended approach would be use the Remix Express template since that exposes express directly Github discussion Remix App Server TemplateFor folks using the Remix App server template, perhaps 1 approach would be to create a utility function (ex: Pros:
Cons:
// Kents code from post ^^
const upgradeToHttps = (request: Request) => {
// upgrade people to https automatically
let url = new URL(request.url);
let hostname = url.hostname;
let proto = request.headers.get("X-Forwarded-Proto") ?? url.protocol;
url.host =
request.headers.get("X-Forwarded-Host") ??
request.headers.get("host") ??
url.host;
url.protocol = "https:";
if (proto === "http" && hostname !== "localhost") {
return redirect(url.toString(), {
headers: {
"X-Forwarded-Proto": "https",
},
});
}
}
// call at root loader
export let loader: LoaderFunction = ({ request }) => {
upgradeToHttps(request)
}; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I had to do this and it felt like something that should happen for me automagically.
Beta Was this translation helpful? Give feedback.
All reactions