// 宇森游戏 · 前端与 Odoo 通信层 // 本地调试:前端 8888 -> Odoo 8069(跨域,带调试 CORS 头) // 生产部署:前端与 Odoo 同域,由 nginx 代理 /game/*。 const API_CONFIG = { base: (location.hostname === '127.0.0.1' && location.port === '8888') ? 'http://127.0.0.1:8069' : (location.hostname === 'localhost' && location.port === '8888') ? 'http://127.0.0.1:8069' : '', db: (location.hostname === '127.0.0.1' && location.port === '8888') ? 'study' : 'game', }; const _cred = API_CONFIG.base ? 'include' : 'same-origin'; function _url(path) { return `${API_CONFIG.base}${path}?db=${API_CONFIG.db}`; } const API = { async me() { return (await fetch(_url('/game/api/me'), { credentials: _cred })).json(); }, async login(login, password) { return (await fetch(_url('/game/api/login'), { method: 'POST', credentials: _cred, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ login, password }), })).json(); }, async register(payload) { return (await fetch(_url('/game/api/register'), { method: 'POST', credentials: _cred, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), })).json(); }, async logout() { return (await fetch(_url('/game/api/logout'), { method: 'POST', credentials: _cred, })).json(); }, async codex() { return (await fetch(_url('/game/api/codex'), { credentials: _cred })).json(); }, async rules() { return (await fetch(_url('/game/api/rules'), { credentials: _cred })).json(); }, async currencies() { return (await fetch(_url('/game/api/currencies'), { credentials: _cred })).json(); }, async pages() { return (await fetch(_url('/game/api/pages'), { credentials: _cred })).json(); }, async threads() { return (await fetch(_url('/game/api/threads'), { credentials: _cred })).json(); }, async announcements() { return (await fetch(_url('/game/api/announcements'), { credentials: _cred })).json(); }, };