14 lines
598 B
Plaintext
14 lines
598 B
Plaintext
# 多租户域名路由:解析当前请求域名对应的租户/分销商
|
|
env = request._run_ns
|
|
host = request.headers.get('X-Forwarded-Host') or request.host
|
|
host = host.split(':')[0]
|
|
try:
|
|
rec = await env.get_domain_by_host(request, host)
|
|
except Exception as e:
|
|
return json.dumps({'success': False, 'domain': host, 'error': str(e)}, ensure_ascii=False)
|
|
if rec:
|
|
result = {'success': True, 'domain': host, 'resellerid': rec.resellerid, 'orgid': rec.orgid}
|
|
else:
|
|
result = {'success': False, 'domain': host, 'error': 'Domain not found'}
|
|
return json.dumps(result, ensure_ascii=False)
|