Skip to content

Commit

Permalink
feat: remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhaidong committed Dec 25, 2024
1 parent 1270c38 commit 800db19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions sea/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ def _register_extension(self, name, ext):
self._extensions[name] = ext

def load_middlewares(self):
env_mids = os.environ.get("SEA_MIDDLEWARES", "").split(",")
mids = ["sea.middleware.GuardMiddleware"] + [mid for mid in env_mids if mid] + self.config.get("MIDDLEWARES")
config_mids = self.config.get("MIDDLEWARES")
mids_from_env = os.environ.get("SEA_MIDDLEWARES", "").split(",")
env_mids = [mid for mid in mids_from_env if mid and mid not in config_mids]
mids = ["sea.middleware.GuardMiddleware"] + env_mids + config_mids
for mn in mids:
m = utils.import_string(mn)
self._middlewares.insert(0, m)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_baseapp(caplog):
assert _app.config["PORT"] == 4001
assert _app.debug
assert _app.testing
os.environ["SEA_MIDDLEWARES"] = "sea.middleware.BaseMiddleware,"
os.environ["SEA_MIDDLEWARES"] = "sea.middleware.BaseMiddleware,sea.middleware.ServiceLogMiddleware,"
_app.load_middlewares()

assert len(_app.middlewares) == 4
Expand Down

0 comments on commit 800db19

Please sign in to comment.