content: Android Capacitor origin is `https://localhost` by default, not `http://localhost`

未关闭 适合新手
#4,546 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
80/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
冷清
技术栈
android
领域
documentation

调研方向

打开 issue URL 中的 CORS 故障排除页面,并检查描述 Capacitor origins 的段落。更新该段落,说明 Android 默认使用 https://localhost,解释 server.androidScheme 覆盖项,并确认措辞与链接的 Capacitor 配置参考一致。

由索引模型根据 Issue 内容生成。

描述

triage
URL

https://ionicframework.com/docs/troubleshooting/cors#what-is-cors

Issue Description

Summary

The CORS docs state that the Android origin is http://localhost. On current Capacitor this is https://localhost by default, because server.androidScheme defaults to https. The current wording leads people to whitelist the wrong origin and get blocked requests on Android.

What the docs say

From the CORS page:

An origin is the combination of the protocol, domain, and port from which your Ionic app or the external resource is served. For example, apps running in Capacitor have capacitor://localhost (iOS) or http://localhost (Android) as their origin.

What actually happens

On a default Capacitor app (no androidScheme set), the Android webview origin is https://localhost, not http://localhost.

Tested on Capacitor 7 with a production backend. The server logged the incoming Origin header per platform:

Android        origin = https://localhost
iOS / iPadOS   origin = capacitor://localhost

The CORS allowlist only started working on Android after adding https://localhost. Adding http://localhost had no effect.

Why

Since Capacitor 6 made https the default androidScheme, the default Android origin is https://localhost. Per the config reference, the origin is androidScheme + hostname. It is http://localhost only if you set androidScheme: 'http'. Also raised in #3639.

Suggested wording

Apps running in Capacitor have capacitor://localhost (iOS) or https://localhost (Android) as their origin by default. The Android scheme follows server.androidScheme, which defaults to https. It is http://localhost only if you set androidScheme: 'http'.

If this looks right, I am happy to open a PR with the change.

主要语言
MDX
星标
621
派生
3.2k
平均合并
1 天 2 小时
30 天内合并 PR
86

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ionic-team/ionic-docs 的其他 Issue

查看 ionic-team/ionic-docs 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。