Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sanic ip whitelist

whitelist = ["127.0.0.1"]
@app.on_request
async def on_request(request):
    user_ip = request.remote_addr or request.ip
    if (not user_ip in whitelist):
        return text("Nice try", status=403) # 403 = forbidden
      # no need to write an else; the requested method will run.
 
PREVIOUS NEXT
Tagged: #sanic #ip #whitelist
ADD COMMENT
Topic
Name
8+9 =