fix(game_base): rebuild db-aware routing patch to fix game.pengyuthon.cn login 404
- rebuild models/ir_http.py: monkeypatch Request._get_session_and_dbname bind DB by URL prefix (/game/->game, /yt_world/->yt_game), guarded by db_filter - __init__.py import ir_http to load the patch - root cause: dbfilter=^(pengyuthon|school|test|yun|game)$, nginx proxies /game/ with Host:game.pengyuthon.cn; host cannot resolve db -> nodb route table -> /game/api/* 404, login fails - after fix /game/api/codex and /game/api/login return 200
This commit is contained in:
parent
cb34f00153
commit
f78f37d677
@ -5,3 +5,4 @@ from . import rule_category
|
|||||||
from . import rule
|
from . import rule
|
||||||
from . import page
|
from . import page
|
||||||
from . import story
|
from . import story
|
||||||
|
from . import ir_http
|
||||||
|
|||||||
48
addons/game_base/models/ir_http.py
Normal file
48
addons/game_base/models/ir_http.py
Normal file
@ -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/)")
|
||||||
Loading…
Reference in New Issue
Block a user