我有一个正在本地开发的 React Native Expo 应用程序,它在 Pixel 8 Android 模拟器上运行。当向后端发送 http 请求时,我收到“TypeError:网络请求失败”。当我查看从 docker compose 文件运行的 traefik 代理的日志时,我看到一条错误:“http:来自 172.22.0.1:40280 的 TLS 握手错误:远程错误:tls:未知证书”。
我已经尝试过:
这是我的配置文件,可能与追踪问题相关:
# app.json
{
"expo": {
"jsEngine": "hermes",
"name": "myapp",
"slug": "mobileapp",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"jsEngine": "hermes",
"supportsTablet": true,
"bundleIdentifier": "com.myapp.mobileapp"
},
"userInterfaceStyle": "automatic",
"android": {
"jsEngine": "hermes",
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#4149b0"
},
"softwareKeyboardLayoutMode": "pan",
"package": "com.myapp.mobileapp"
},
"web": {
"favicon": "./assets/favicon.png",
"bundler": "metro"
},
"plugins": [
[
"expo-font",
{
"fonts": [
"./assets/fonts/SourceSans3Bold.ttf",
"./assets/fonts/SourceSans3SemiBold.ttf",
"./assets/fonts/SourceSans3Medium.ttf",
"./assets/fonts/SourceSans3Regular.ttf"
]
}
],
[
"expo-secure-store",
{
"faceIDPermission": "Allow $(PRODUCT_NAME) to access your Face ID biometric data.",
"touchIDPermission": "Allow $(PRODUCT_NAME) to access your Touch ID biometric data."
}
],
[
"./withAndroidPlaid.js"
]
]
}
}
# docker-compose.yml
...
proxy:
image: traefik:v2.10
command:
- "--api.insecure=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entryPoints.websecure.forwardedHeaders.insecure"
# ^^ needed so that we can check ip address of the ory webhook response in the django middleware
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.file.directory=/traefik"
- "--providers.file.watch=true"
- "--log.level=DEBUG"
ports:
- 80:80
- 443:443
- 8080:8080
volumes:
- ./front/certs:/etc/ssl/certs
- ./traefik:/traefik
- /var/run/docker.sock:/var/run/docker.sock
...
# traefik.config
tls:
certificates:
- certFile: /etc/ssl/certs/localhost.crt
keyFile: /etc/ssl/certs/localhost.key
事实证明,这是 docker compose 文件中 traeifk 标签规则的问题。这解决了问题:
- "traefik.http.routers.api.rule=(HostRegexp(`localhost|10.0.2.2`) && PathPrefix(`/v{version:[0-9]+}/`))"
- "traefik.http.routers.api.entrypoints=websecure"
- "traefik.http.routers.api.tls=true"
- "traefik.http.routers.api.middlewares=cors@docker, oathkeeper"