示例#1
0
 def build_app_init(self, config={}, **limiter_args):
     app = Sanic(__name__)
     for k, v in config.items():
         app.config.setdefault(k, v)
     limiter_args.setdefault('key_func', get_remote_address)
     limiter = Limiter(**limiter_args)
     limiter.init_app(app)
     mock_handler = mock.Mock()
     mock_handler.level = logging.INFO
     limiter.logger.addHandler(mock_handler)
     return app, limiter
示例#2
0
文件: __init__.py 项目: yc19890920/ap
app.blueprint(openapi_blueprint)
app.blueprint(swagger_blueprint)

redis = SanicRedis(app)
CORS(app, automatic_options=True)

app.blueprint(crud_bp)
# 接口访问限制
# app.config.RATELIMIT_STORAGE_URL = 'redis://127.0.0.1:6379'
limiter = Limiter(app,
                  global_limits=['10000 per hour', '100000 per day'],
                  key_func=get_remote_address,
                  # storage_uri='redis://localhost:6379/1'
                  )
limiter.init_app(app)
limiter.limit("1000 per hour")(crud_bp)
# limiter.exempt(crud_bp)


# JWT 配置
# jwt 返回jwt 获取token的键设置,将改变默认键 access_token
app.config.SANIC_JWT_ACCESS_TOKEN_NAME = 'sanic-token'
# app.config.SANIC_JWT_ACCESS_TOKEN_NAME = 'jwt'

# 设置过期时间, 默认30分钟
# app.config['JWT_EXPIRATION_DELTA'] = datetime.timedelta(days=10)
app.config['JWT_EXPIRATION_DELTA'] = datetime.timedelta(seconds=60)

initialize(
    app,