Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for middleware class in add_middleware method #38

Open
Daxexs opened this issue Feb 14, 2025 · 0 comments
Open

Add support for middleware class in add_middleware method #38

Daxexs opened this issue Feb 14, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Daxexs
Copy link
Owner

Daxexs commented Feb 14, 2025

Note: supports async

Example:

import flet_easy as fs
import flet as ft

app = fs.FletEasy()


def starting_page(data: fs.Datasy):
    print(f"\n⚡[MIDDLEWARES RUNNING]\n-> Route:{data.route}\n1. Loading the page")


async def starting_page_two(data: fs.Datasy):
    # ("2. Loading the page")
    routes = [
        "/dashboard",
    ]
    if data.route not in routes:
        print("-> Redirection to path (/l)")
        return data.redirect("/")


# add class to middleware custom
class CustomMiddlewareInit(fs.MiddlewareRequest):
    def before_request(self):
        print("/// (app-root) Before request", self.data)

    async def after_request(self):
        print("/// (app-root) After request")


app.add_middleware([starting_page, starting_page_two, CustomMiddlewareInit])

@app.page("/", title="index")
def home(data:fs.Datasy):
      return ft.View(
        controls=[
            ft.Text("Home page"),
       ]
     )

app.run()
@Daxexs Daxexs added the enhancement New feature or request label Feb 14, 2025
@Daxexs Daxexs self-assigned this Feb 14, 2025
@Daxexs Daxexs moved this to In progress in Flet-Easy Development Feb 14, 2025
@Daxexs Daxexs moved this from In progress to In review in Flet-Easy Development Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In review
Development

No branches or pull requests

1 participant