I'm using PostMan to troubleshoot an odd 400 error with my Angular / NodeJS app.
I'm trying to GET https://example.com/login.html
and the request has two headers:
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGc...==
and Accept: text/html
This returns a 400 Bad Request
error (server: cloudflare-nginx)
This works fine (returns 200
) if:
I access the file in my local environment on
http://localhost:5000/login.html
(no https factor?) -or-I remove
Authorization: Bearer
from the header
If I watch my NodeJS server logs, I don't even see the request come through. So /login.html
doesn't even get hit, I assume because Express is rejecting it before my app.use(logger('dev'));
picks it up.
UPDATE: I believe Cloudflare is kicking it back with 400 prior to the request ever reaching Heroku.
A few more points:
I am using JWT to authenticate users, which is where the Bearer token comes from.
If I access other endpoints, such as
/profile
with the Bearer token, it responds properly with the user profile from decoding the token.
My question is:
Why would this request be a "Bad Request" when it works on other endpoints?
Is there a way to catch this and do something with the request before it's returned as 400?