You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义域名下GitHub Pages无法回传Cookie的CORS/DNS问题排查

问题描述
  • 前端基于Angular,部署在GitHub Pages;后端基于Google Cloud Functions/Node.js
  • 前端通过Angular HttpClient向/api/user/create发送POST请求,已配置{ withCredentials: true }
  • 直接访问GitHub Pages原生域名https://striderhobbit.github.io/psycho-cli时,所有功能正常
  • 配置自定义域名https://www.tecstures.com后出现异常:
    • 登录请求可正常收到响应Cookie,详情如下:
      connect.sid 
      expires "2024-04-09T09:06:23.000Z"
      path    "/"
      samesite    "None"
      secure  true
      value   "s:p6moM7Q_zD50xUsCl2ns8kA608tE1qb4.zkz7Y91fcqs+YTfVdtKV4yAqnTofhPogvhdWMo0g2yQ"
      
    • 但/api/user/create请求多数情况下失败,开发者工具显示请求Cookie为空,导致会话丢失;仅极少数场景无需修改代码即可正常运行
  • 已排除服务器响应时间问题,确定异常与GitHub Pages的自定义域名设置直接相关
后端核心代码

后端采用express+express-session实现,核心配置代码如下:

const app = express();

app.use(
  cors({
    origin: ["https://tecstures.com", "https://striderhobbit.github.io"],
    credentials: true,
  })
);
app.set("trust proxy", true);
app.use(express.json());
app.use(
  session({
    cookie: {
      maxAge: 300000,
      httpOnly: false,
      secure: true,
      sameSite: "none",
      partitioned: true,
    },
    resave: false,
    saveUninitialized: false,
    secret: generate(10),
  })
);
复现信息更新

访问https://tecstures.com/#/events,按指定步骤操作可稳定复现问题,执行后抛出错误:

Error: Missing authentication at EventService.authorize (/workspace/lib/src/services/base.js:13:19)...

内容的提问来源于stack exchange,提问作者striderhobbit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 05:50:05