From fa4dfa3a3f884e9c55eb96bf777df821a1730e48 Mon Sep 17 00:00:00 2001 From: pengyuthon Date: Sat, 25 Jul 2026 23:20:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(game=5Fbase):=20=C3=96=D8=BD=C2=A8=20db-awa?= =?UTF-8?q?re=20=C2=B7=C3=93=C9=B2=C2=B9=C2=B6=C2=A1=C3=90=DE=B8=C2=B4=20g?= =?UTF-8?q?ame.pengyuthon.cn=20=C2=B5=C3=87=C2=BC404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Öؽ¨ models/ir_http.py: monkeypatch Request._get_session_and_dbname °´ URL ǰ׺ǿÖưó¶¨Êý¾ݿâ (/game/->game, /yt_world/->yt_game) Óà db_filter ÊØÎÀ, ±ÜÃâÎÛȾ nodb ·ÓÉ - __init__.py ׷¼Ó from . import ir_http ÒԼÓÔز¹¶¡ - ¸ùÒò: Odoo18 dbfilter=^(pengyuthon|school|test|yun|game)$, nginx ÒÔ Host:game.pengyuthon.cn ·´´ú /game/ ʱÎ޷¨´Ó Host ÍƿâÃû, ×ß nodb ·Óɱíµ¼Ö /game/api/* 404¡¢µÇ¼½ø²»ȥ - Ð޸´ºó /game/api/codex Óë /game/api/login ÓÉ 404->200 --- addons/game_base/models/__init__.py | 1 + addons/game_base/models/ir_http.py | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 addons/game_base/models/ir_http.py diff --git a/addons/game_base/models/__init__.py b/addons/game_base/models/__init__.py index 42dfeb2..634af88 100644 --- a/addons/game_base/models/__init__.py +++ b/addons/game_base/models/__init__.py @@ -5,3 +5,4 @@ from . import rule_category from . import rule from . import page from . import story +from . import ir_http diff --git a/addons/game_base/models/ir_http.py b/addons/game_base/models/ir_http.py new file mode 100644 index 0000000..b2aec05 --- /dev/null +++ b/addons/game_base/models/ir_http.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +""" +YUSEN db-aware routing patch for Odoo 18. + +Odoo 18 resolves the database from the Host header via dbfilter. The +yt.pengyuthon.cn front-end proxies /game/ and /yt_world/ requests to Odoo +with Host "game.pengyuthon.cn" (a virtual host), which does NOT match the +fixed dbfilter list. As a result those requests fall through to the +database-free routing map and return 404. + +This patch forces the correct database for path-prefixed game routes so the +real controllers (game_base) are reachable. +""" +import logging + +_logger = logging.getLogger(__name__) + +import odoo.http +from odoo.http import Request, db_filter + +# path prefix -> target database +PATH_DB_MAP = { + '/game/': 'game', + '/yt_world/': 'yt_game', +} + +_ORIG_get_session_and_dbname = Request._get_session_and_dbname + + +def _patched_get_session_and_dbname(self): + path = self.httprequest.path + host = self.httprequest.environ.get('HTTP_HOST', '') + for prefix, db in PATH_DB_MAP.items(): + if path.startswith(prefix): + # only force the db if it actually passes the configured dbfilter, + # otherwise degrade gracefully to Odoo's default resolution + if db_filter([db], host=host): + session, _ = _ORIG_get_session_and_dbname(self) + session.db = db + return session, db + break + return _ORIG_get_session_and_dbname(self) + + +if not getattr(Request._get_session_and_dbname, '_yusen_db_patch', False): + _patched_get_session_and_dbname._yusen_db_patch = True + Request._get_session_and_dbname = _patched_get_session_and_dbname + _logger.info("YUSEN patched Request._get_session_and_dbname (db-aware routing for /game/ and /yt_world/)")