admin管理员组文章数量:1279120
The frontend is on app.example.test
. The backend is on api.example.test
. The error I'm getting is CORS error
on fetch
but getting ok
200 on preflight:
Using local host in /etc/hosts
to emulate real link:
127.0.0.1 example.test api.example.test app.example.test
Axum CORS config:
let cors = CorsLayer::new()
.allow_methods([Method::GET, Method::POST, Method::PATCH, Method::DELETE])
.allow_origin(";.parse::<HeaderValue>().unwrap())
.allow_headers([CONTENT_TYPE, AUTHORIZATION]);
let app = Router::new()
.nest("/nodes", nodes::nodes_router(app_state.clone()))
.nest("/trees", trees::trees_router(app_state.clone()))
.nest("/webhooks", auth::webhooks_router())
.with_state(app_state)
.layer(cors);
Nginx config:
server {
listen 80;
listen [::]:80;
server_name app.example.test;
location / {
proxy_pass http://fekr-frontend:5173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
listen [::]:80;
server_name api.example.test;
location / {
proxy_pass http://fekr-backend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Docker compose:
backend:
container_name: fekr-backend
build:
context: ./backend
dockerfile: Dockerfile
target: final
ports:
- "3000:3000"
environment:
DATABASE_URL: $DATABASE_URL
JWKS_URL: $JWKS_URL
WEBHOOK_SECRET: $WEBHOOK_SECRET
command: cargo run
depends_on:
- db
frontend:
container_name: fekr-frontend
stdin_open: true
build:
context: ./frontend
dockerfile: Dockerfile
volumes:
- ./frontend:/app
- /app/node_modules
ports:
- "5173:5173"
environment:
- CHOKIDAR_USEPOLLING=true
command: npm run dev-exposed
Lastly, if I set allow origin to any .allow_origin(Any)
it works.
本文标签: dockerAxum is returning CORS error on virtual local hostStack Overflow
版权声明:本文标题:docker - Axum is returning CORS error on virtual local host - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741247540a2365169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论