#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""确认真实用户链路的最后一段：CDN 外壳 → 隧道 API 是否已带出新接口。

判据：不带 token 请求应返回 401（= 路由存在、只是没身份）；
返回 404「未知接口」才说明隧道后面还是旧后端。
"""
import json
import ssl
import urllib.error
import urllib.request

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

BASE = 'https://api.biorisales.site:8443'
PATHS = ['/api/visit/stats?month=2026-10', '/api/todos']

for p in PATHS:
    try:
        r = urllib.request.urlopen(urllib.request.Request(BASE + p, headers={'User-Agent': 'probe'}),
                                   timeout=20, context=ctx)
        body = r.read()[:150].decode('utf-8', 'ignore')
        print('HTTP %s  %-32s %s' % (r.status, p, body))
    except urllib.error.HTTPError as e:
        body = e.read()[:150].decode('utf-8', 'ignore')
        print('HTTP %s  %-32s %s' % (e.code, p, body))
    except Exception as e:
        print('  失败  %-32s %s' % (p, str(e)[:80]))
