Deny ip addresses?


#1

Hi
Is there a way I can deny access from a specific ip address when they visit my glitch page?
Thanks


#2

The incoming requests originating IP Address should be in the request’s “X-Forwarded-For” header, so you could check that for the IP you want to ban and if you see the one you don’t want you could then return an appropriate response. You could also use something like https://www.npmjs.com/package/express-ip-block if you’re using Express.


#3

I’m using hello webpage though


#4

That’s more complicated. hello-webpage uses https://www.npmjs.com/package/lws for its web server. I don’t think there’s anything built into lws that would handle this (the docs are at https://github.com/lwsjs/local-web-server/wiki) so I think you’re have to write your own middleware to handle it. You’d also have to have a custom config file to load that middleware, once it was in place.


#6

Hey @SpeedyCraftah I thought this might be a fun little project and I’ve been meaning to put together a sample of a custom lws config, so I threw together a little example that should allow you to block an IP address on a hello-webpage-based project.

Take a look at https://glitch.com/~hello-webpage-custom-config and let me know if you have questions.