Share your repls and programming experiences

← Back to all posts
Redirect to https in Node.js
amasad (2399)

If you want to make sure your replit site only serves https you can use this middleware.

AllAwesome497 (356)

I made a version of this that works in flask, here it is:

def force_https():
	if 'X-Forwarded-Proto' in request.headers:
		if request.headers['X-Forwarded-Proto'] == 'http':
			return redirect(request.url.replace('http://', 'https://'))```
JadenGarcia (37)

What if I just did this?

location.href = location.href.replace(/^http:\/\//, "https://");

btw, check out

AdCharity (1264)

wait how does this work with pre-existing middleware (because I have a middleware that checks a JSON file to see if the file is "locked"). I'm concerned that I'll get a "you can't change headers after they've been sent" error, but I'll try it first :P

Edit: works fine but I had to go about some minor changes

MrEconomical (2197)

I always put a script in the client-side to do that lol

nithilan4 (238)


if (window.location.protocol == "http:") 
window.location.protocol = "https:";



@nithilan4 wait does that work?

nithilan4 (238)

@TaylorLiang surprisingly yes but only for things like replit that can be http or https

MrEconomical (2197)

@TaylorLiang yes - I use

Coder100 (3144)

mmmm time to make a package to do that