content: Android Capacitor origin is `https://localhost` by default, not `http://localhost`
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 80/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- android
调研方向
打开 issue URL 中的 CORS 故障排除页面,并检查描述 Capacitor origins 的段落。更新该段落,说明 Android 默认使用 https://localhost,解释 server.androidScheme 覆盖项,并确认措辞与链接的 Capacitor 配置参考一致。
由索引模型根据 Issue 内容生成。
描述
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) orhttps://localhost(Android) as their origin by default. The Android scheme followsserver.androidScheme, which defaults tohttps. It ishttp://localhostonly if you setandroidScheme: 'http'.
If this looks right, I am happy to open a PR with the change.
- 主要语言
- MDX
- 星标
- 621
- 派生
- 3.2k
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 86
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/ionic-docs 的其他 Issue
-
content
难度 2/5 1-3 小时 新手友好度 86/100
ionic-team/ionic-docs#4705 ·
-
content package: angular
难度 2/5 半天 新手友好度 78/100
ionic-team/ionic-docs#4702 ·
-
content
难度 2/5 1-3 小时 新手友好度 68/100
ionic-team/ionic-docs#4381 · 2 条评论 ·
-
triage
难度 1/5 1 小时以内 新手友好度 72/100
ionic-team/ionic-docs#3639 ·
-
content package: angular
难度 2/5 1-3 小时 新手友好度 62/100
ionic-team/ionic-docs#3583 ·
查看 ionic-team/ionic-docs 的全部 Issue
相似的 Issue
-
documentation help wanted
难度 2/5 1-3 小时 新手友好度 90/100
-
user-reported
难度 2/5 1-3 小时 新手友好度 85/100
Kong/developer.konghq.com#7316 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
HarperFast/skills#96 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 82/100
infinispan/infinispan#18150 ·