Created
September 25, 2017 18:45
-
-
Save fooker/48fdad260ff5b110943004f565729c50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bottle | |
import functools | |
private = bottle.Bottle() | |
@private.get('/') | |
def private_index(): | |
return 'Follow the white rabbit.'; | |
@bottle.get('/') | |
def public_index(): | |
return 'Knock, Knock, Knock, Neo.'; | |
def auth(callback): | |
@functools.wraps(callback) | |
def wrapper(*args, **kwargs): | |
if bottle.request.remote_addr not in ('::1', '127.0.0.1'): | |
bottle.abort(401, 'Go away!') | |
else: | |
return callback(*args, **kwargs) | |
return wrapper | |
if __name__ == '__main__': | |
private.install(auth) | |
bottle.mount(prefix='/private', app=private) | |
bottle.run(host=('::'), port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment