I would need help with my deployment issue on “fly.io” platform. Communication between the frontend and backend is functional for a while, but then this error occurs:
“Acess to XMLHttpRequest at ‘https://todo-backend.fly.dev’ from origin ‘https://todo-frontend.fly.dev’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”
where the problem is that I am not sending the header from the frontend to the backend, which was previously being sent and suddenly stopped. My application works fine until I transferred it to this platform. May I ask how someone else solved this issue?
My backend configuration is as follows:
app.use(
cors({
origin: [
"https://todo-front.fly.dev",
],
credentials: true,
})
);
backend log:
enter image description here
And this is my frontend configuration:
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'https://todo-frontend.fly.dev',
}),
responseType: 'text' as 'json',
withCredentials: true,
};
fly.toml frontend:
app = "todo-front"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
fly.toml backend:
app = "todo-back"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
ALLOWED_ORIGINS = "https://todo-frontend.fly.dev"
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 3000
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
Thank you in advance
I have tried to change ‘Access-Control-Allow-Origin’: ‘https://todo-frontend.fly.dev’ to
‘Access-Control-Allow-Origin’: ‘*’ etc. nothing works. Is it problem of the hosting?