Hello,
I am having an issue that I cannot get any response from my app deployed on fly.io.
I put bearer token on Authorization headers with each request for firebase authentication.
I am using Rails7 for backend API (fly.io).
Console errors shown on client side.
XMLHttpRequest at 'https://{my app name}.fly.dev from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js?1a5c:220 GET https://{my app name}.fly.dev net::ERR_FAILED 502
Cors setting using rack cors gem.
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3001', 'https://{frontend url}'
resource "*",
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
There is no problem on development invironment. I also deployed my Rails app on heroku, and it works without any problem. So I guess the problem causes only on fly.io …?
2022-09-12T05:31:55.400 app[24ed76e9] nrt [info] I, [2022-09-12T05:31:55.400469 #521] INFO -- : [2768073f-9765-4069-8b85-5e3e022d33ae] Started GET "/api/v1/companies" for 137.66.0.124 at 2022-09-12 05:31:55 +0000
2022-09-12T05:31:55.401 app[24ed76e9] nrt [info] I, [2022-09-12T05:31:55.401356 #521] INFO -- : [2768073f-9765-4069-8b85-5e3e022d33ae] Processing by Api::V1::CompaniesController#index as JSON
2022-09-12T05:31:55.402 app[24ed76e9] nrt [info] I, [2022-09-12T05:31:55.400950 #521] INFO -- : [3a6aa8cb-8485-48a6-93e5-5c224c4be314] Started GET "/api/v1/works" for 137.66.0.124 at 2022-09-12 05:31:55 +0000
2022-09-12T05:31:55.402 app[24ed76e9] nrt [info] I, [2022-09-12T05:31:55.402466 #521] INFO -- : [3a6aa8cb-8485-48a6-93e5-5c224c4be314] Processing by Api::V1::WorksController#index as JSON
2022-09-12T05:32:06.331 app[24ed76e9] nrt [info] I, [2022-09-12T05:32:06.331431 #521] INFO -- : [4fed247d-df9f-4f64-a830-92fb6ea86fe7] Completed 200 OK in 240288ms (Views: 0.3ms | ActiveRecord: 3.0ms | Allocations: 18968)
It took long time to process, and finally got Completed 200. However, the client side actually got 502 error.
This happen only when I put “Authorization bearer token” on request headers to use firebase auth.
Thus, I am guessing that adding something on request headers causes problems on fly.io.
Ah, thats probably the issue. fly.io has a timeout of 2 minutes, if your app doesn’t respond in that time then fly.io considers that request as failed and returns a 502.