chucknorris-io / chuck-api

👊 chucknorris.io is a free resource for hand curated Chuck Norris facts.
https://api.chucknorris.io
GNU General Public License v3.0
239 stars 29 forks source link

CORS once again - Internal Server Error 500 when Origin header set #48

Closed maral closed 4 months ago

maral commented 4 months ago

Hi, after yesterday's outage and the following fixes, it seems the CORS stopped working again. Namely, in #28 for example you state that it's enough to add the Origin header to the request and it should add the correct response header, however there seems to be an Internal Server Error now:

# curl -H 'Origin: http://localhost:3001' -i 'https://api.chucknorris.io/jokes/random'
HTTP/2 500 
date: Wed, 19 Jun 2024 09:25:14 GMT
content-type: application/json
report-to: {"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1718789114&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=QLtBANkj7RFTHDIP6uP3q5XodZJc2ipxBJEE8yDXEAw%3D"}]}
reporting-endpoints: heroku-nel=https://nel.heroku.com/reports?ts=1718789114&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=QLtBANkj7RFTHDIP6uP3q5XodZJc2ipxBJEE8yDXEAw%3D
nel: {"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]}
vary: Origin
vary: Access-Control-Request-Method
vary: Access-Control-Request-Headers
via: 1.1 vegur
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 8962787c091f1c05-FRA
alt-svc: h3=":443"; ma=86400

{"timestamp":"2024-06-19T09:25:14.273Z","status":500,"error":"Internal Server Error","path":"/jokes/random"}

Or does the problem lie between my chair and my keyboard once again?

matchilling commented 4 months ago

Issue was fixed in https://github.com/chucknorris-io/chuck-api/commit/918d3272d0ce7c3661a05db3f452ce3a62a8b1a7

maral commented 4 months ago

Great, I appreciate it. It now doesn't return 500 anymore, however it's missing the access-control-allow-origin header in the response, so it still doesn't work in browsers:

# curl -H 'Origin: http://localhost:3001' -i 'https://api.chucknorris.io/jokes/random'
HTTP/2 200
date: Wed, 19 Jun 2024 11:44:23 GMT
content-type: application/json
report-to: {"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1718797463&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=zeTdATPVEkfLPQB0c45qfAlNs9glO3RHAjujBY3z2Nw%3D"}]}
reporting-endpoints: heroku-nel=https://nel.heroku.com/reports?ts=1718797463&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=zeTdATPVEkfLPQB0c45qfAlNs9glO3RHAjujBY3z2Nw%3D
nel: {"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]}
via: 1.1 vegur
cf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 896344542cb19f2a-FRA
alt-svc: h3=":443"; ma=86400

{"categories":[],"created_at":"2020-01-05 13:42:26.194739","icon_url":"https://assets.chucknorris.host/img/avatar/chuck-norris.png","id":"CpM7NFI7Qeq1ublS1WuMaw","updated_at":"2020-01-05 13:42:26.194739","url":"https://api.chucknorris.io/jokes/CpM7NFI7Qeq1ublS1WuMaw","value":"Chuck Norris can clip his toenails, blow up a balloon, sneeze and inhale a cigarette at the same time."}
matchilling commented 4 months ago

Will take another look at it later today

El dc, 19 juny 2024 a les 13:45 Marek Lisy @.***> va escriure:

Great, I appreciate it. It now doesn't return 500 anymore, however it now doesn't include the access-control-allow-origin header, so it still doesn't work in browsers:

curl -H 'Origin: http://localhost:3001' -i 'https://api.chucknorris.io/jokes/random'

HTTP/2 200 date: Wed, 19 Jun 2024 11:44:23 GMT content-type: application/json report-to: {"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1718797463&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=zeTdATPVEkfLPQB0c45qfAlNs9glO3RHAjujBY3z2Nw%3D"}]} reporting-endpoints: heroku-nel=https://nel.heroku.com/reports?ts=1718797463&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=zeTdATPVEkfLPQB0c45qfAlNs9glO3RHAjujBY3z2Nw%3D nel: {"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]} via: 1.1 vegur cf-cache-status: DYNAMIC server: cloudflare cf-ray: 896344542cb19f2a-FRA alt-svc: h3=":443"; ma=86400

{"categories":[],"created_at":"2020-01-05 13:42:26.194739","icon_url":"https://assets.chucknorris.host/img/avatar/chuck-norris.png","id":"CpM7NFI7Qeq1ublS1WuMaw","updated_at":"2020-01-05 13:42:26.194739","url":"https://api.chucknorris.io/jokes/CpM7NFI7Qeq1ublS1WuMaw","value":"Chuck Norris can clip his toenails, blow up a balloon, sneeze and inhale a cigarette at the same time."}

— Reply to this email directly, view it on GitHub https://github.com/chucknorris-io/chuck-api/issues/48#issuecomment-2178492476, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACLDMHPYNZ7RZN43OYOMYYTZIFVO3AVCNFSM6AAAAABJRVLRJGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGQ4TENBXGY . You are receiving this because you modified the open/close state.Message ID: @.***>

matchilling commented 4 months ago

Fixed it ...

$ curl -H 'Origin: http://localhost:3001' -i ' https://api.chucknorris.io/jokes/random'

HTTP/2 200

date: Wed, 19 Jun 2024 18:15:56 GMT

content-type: application/json

report-to: {"group":"heroku-nel","max_age":3600,"endpoints":[{"url":" https://nel.heroku.com/reports?ts=1718820956&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=KbKh7kX5w%2Fy7Z47TSACWAW0sripkZ94QvzYQXH89Y90%3D "}]}

reporting-endpoints: heroku-nel= https://nel.heroku.com/reports?ts=1718820956&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=KbKh7kX5w%2Fy7Z47TSACWAW0sripkZ94QvzYQXH89Y90%3D

nel: {"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]}

vary: Origin

vary: Access-Control-Request-Method

vary: Access-Control-Request-Headers

access-control-allow-origin: *

access-control-expose-headers: Access-Control-Allow-Origin Access-Control-Allow-Credentials

via: 1.1 vegur

cf-cache-status: DYNAMIC

server: cloudflare

cf-ray: 896581de98346617-MAD

alt-svc: h3=":443"; ma=86400

{"categories":[],"created_at":"2020-01-05 13:42:26.194739","icon_url":" https://assets.chucknorris.host/img/avatar/chuck-norris.png","id":"ElJk2Y3AR6qCO-DgQdjD2A","updated_at":"2020-01-05 13:42:26.194739","url":" https://api.chucknorris.io/jokes/ElJk2Y3AR6qCO-DgQdjD2A","value":"Thi site has the worst Chuck Norris jokes out there. I mean really people. No one even puts any thought into them. They are pathetic"

On Wed, Jun 19, 2024 at 2:13 PM Matías J. Schilling < @.***> wrote:

Will take another look at it later today

El dc, 19 juny 2024 a les 13:45 Marek Lisy @.***> va escriure:

Great, I appreciate it. It now doesn't return 500 anymore, however it now doesn't include the access-control-allow-origin header, so it still doesn't work in browsers:

curl -H 'Origin: http://localhost:3001' -i '

https://api.chucknorris.io/jokes/random' HTTP/2 200 date: Wed, 19 Jun 2024 11:44:23 GMT content-type: application/json report-to: {"group":"heroku-nel","max_age":3600,"endpoints":[{"url":" https://nel.heroku.com/reports?ts=1718797463&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=zeTdATPVEkfLPQB0c45qfAlNs9glO3RHAjujBY3z2Nw%3D"}]}

reporting-endpoints: heroku-nel= https://nel.heroku.com/reports?ts=1718797463&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=zeTdATPVEkfLPQB0c45qfAlNs9glO3RHAjujBY3z2Nw%3D nel: {"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]}

via: 1.1 vegur cf-cache-status: DYNAMIC server: cloudflare cf-ray: 896344542cb19f2a-FRA alt-svc: h3=":443"; ma=86400

{"categories":[],"created_at":"2020-01-05 13:42:26.194739","icon_url":" https://assets.chucknorris.host/img/avatar/chuck-norris.png","id":"CpM7NFI7Qeq1ublS1WuMaw","updated_at":"2020-01-05 13:42:26.194739","url":" https://api.chucknorris.io/jokes/CpM7NFI7Qeq1ublS1WuMaw","value":"Chuck Norris can clip his toenails, blow up a balloon, sneeze and inhale a cigarette at the same time."}

— Reply to this email directly, view it on GitHub < https://github.com/chucknorris-io/chuck-api/issues/48#issuecomment-2178492476>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACLDMHPYNZ7RZN43OYOMYYTZIFVO3AVCNFSM6AAAAABJRVLRJGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGQ4TENBXGY>

. You are receiving this because you modified the open/close state.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/chucknorris-io/chuck-api/issues/48#issuecomment-2178547035, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACLDMHOVDC4BPGG56IQM3CDZIFYXLAVCNFSM6AAAAABJRVLRJGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGU2DOMBTGU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

maral commented 4 months ago

I confirm, it's working now. Thanks a lot and kudos for the work you do! ❤️