Protected static files?


#1

I have a .html file that is generated by my frontend bundler which contains cache-busting files. This .html file basically serves as an entry point to an SPA.
In Sanic I use decorators to protect some of the REST API, and I would like to still have Sanic take care of the redirect to login page if a user is not logged in, or granting access. Basically I was trying to do this:

@auth.login_required
bp.static('/protected', './static/protected_file.html')

Any ideas on how to achieve this or something similar?

Thank you!

Edit: Ok I solved it, I should have RTFM more carefully. :slight_smile:

@bp.route('/protected')
@auth.login_required
async def protected(request):
    return await response.file('./static/protected_file.html')