full-stack-fastapi-template
full-stack-fastapi-template copied to clipboard
backend receiving wrong http scheme
Request is receiving http instead of https. I think it's due to some settings in the traefik dockerfile but I can't figure which setting is causing this. Here's part of the docker-compose file.
labels:
# Enable Traefik for this service, to make it available in the public network
- traefik.enable=true
# Use the traefik-public network (declared below)
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
# Use the custom label "traefik.constraint-label=traefik-public"
# This public Traefik will only use services with this label
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
# traefik-http set up only to use the middleware to redirect to https
- traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
- traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
# Handle host with and without "www" to redirect to only one of them
# Uses environment variable DOMAIN
# To disable www redirection remove the Host() you want to discard, here and
# below for HTTPS
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
# traefik-https the actual router using HTTPS
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
# Use the "le" (Let's Encrypt) resolver created below
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
Did you ever figure this out? I think im having a similar issue. I'm receiving the following response when I make an API call to the backend, even though I direct it to https:
Mixed Content: The page at 'https://XXX' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://XXXX'. This request has been blocked; the content must be served over HTTPS.
For some reason it switches the call to http
I also noticed that navigating to http doesn't auto redirect to https
unfortunately, no. I exactly have the same problem with you. I initially fixed this by replacing http:// with https:// in the client (vuejs). but since I only needed that for my images that I have since moved to firebase storage, I don't have a use for it.
So the issue remains. The solutions I made are workarounds.
I experienced the same problem and after some trying finally found a "solution".
The problem didn't occur on every route, only specific API endpoints seemed to be broken. So after some investigation, I found out that only requests that used query parameters seemed to fail. However, the api/v1/items/?skip=0&limit=10
endpoint still worked fine. Looking at the code in the ItemService
class that issues the request, the URL /api/v1/items/
ends with a /
, which sadly seems to be the only reason why my custom requests failed. After adding that missing trailing /
char, it all worked fine. I know this isn't really a solution, but at least it's an easy fix.
public static readItems(data: TDataReadItems = {}): CancelablePromise<ItemsPublic> {
const {
limit = 100,
skip = 0,
} = data;
return __request(OpenAPI, {
method: 'GET',
url: '/api/v1/items/',
query: {
skip, limit
},
errors: {
422: `Validation Error`,
},
});
}