No response when sending request with firebase auth token

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
app = "my app name"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    BUNDLER_VERSION = "2.3.19"
    NODE_VERSION = "16.16.0"
    RUBY_VERSION = "3.1.2"

[deploy]
  release_command = "bin/rails fly:release"

[env]
  PORT = "8080"
  SERVER_COMMAND = "bin/rails fly:server"

[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"

[[statics]]
  guest_path = "/asdfasdf"
  url_prefix = "/asdfasdf"

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 …?

Does anyone have any ideas?

Hi @kazumi

It looks like your fly app is returning a 502 response. Have you checked your app logs to see if there’s any information?

You can access a live view of the logs using the fly cli or the fly.io dashboard.

Thank you for your reply.

The log doesn’t show any useful information…

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.

Thank you for your reply.

Hmmm,
What makes a long time process?:thinking:
Does fly.io accept request headers and then give us response headers?

Confirmed that it’s working fine now😊

The issue could be related to this post.