Skip to content

Instantly share code, notes, and snippets.

@fooker
Created September 25, 2017 18:45
Show Gist options
  • Save fooker/48fdad260ff5b110943004f565729c50 to your computer and use it in GitHub Desktop.
Save fooker/48fdad260ff5b110943004f565729c50 to your computer and use it in GitHub Desktop.
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