OPTIONS preflight to my PHP API returns HTML without CORS headers

Website URL

https://tracked.infinityfree.io/

Error Message

My API files are in /htdocs/api. GET https://tracked.infinityfree.io/api/ returns JSON, but OPTIONS https://tracked.infinityfree.io/api/messages returns 200 OK with Content-Type: text/html and no Access-Control-Allow-* headers. The request includes Origin: null, Access-Control-Request-Method: POST, and Access-Control-Request-Headers: authorization,content-type. Can you check whether a hosting or proxy rule is intercepting OPTIONS requests to /api/*?

Other Information

My API files are in /htdocs/api. GET https://tracked.infinityfree.io/api/ returns JSON, but OPTIONS https://tracked.infinityfree.io/api/messages returns 200 OK with Content-Type: text/html and no Access-Control-Allow-* headers. The request includes Origin: null, Access-Control-Request-Method: POST, and Access-Control-Request-Headers: authorization,content-type. Can you check whether a hosting or proxy rule is intercepting OPTIONS requests to /api/*?

Welcome to the InfinityFree community forum! Good to have you here.

  • Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
  • Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
  • AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
  • Solving an issue is a joint effort. Try the suggestions you get and report back what happened.

Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.

Yes, that sounds like our browser security system. It isn’t a rule aimed at OPTIONS or /api/*. The check covers every URL on a free account. A preflight sent by a browser can’t run its JavaScript or keep its cookie, so it gets a short HTML page with status 200 instead of reaching your PHP. That fits what you’re seeing: 200 OK, text/html, and no Access-Control-Allow-* headers.

The article on the security system says this about requests that get stopped by it:

If an app, API client or tool reports something like “unexpected content type text/html”, “Unexpected token <” or “JSON parse error at line 1 column 1”, and the response contains aes.js, the request was stopped by the security system and never reached your code.

It also lists cross-site requests (AJAX from other domains, CORS) and REST APIs as things that don’t work on free hosting. Your Origin: null request is cross-site. It says the check can’t be turned off for one path or request method, and that using your own domain doesn’t change that. The only way around it is premium hosting.

Here’s the article:

And a shorter one about APIs:

To confirm it’s the same thing, can you check whether the body of that OPTIONS response contains aes.js or the text “This site requires Javascript to work”? If it does, the request never reached your PHP. If it doesn’t, post the body and I’ll look again.

Your GET to /api/ returned JSON, but that doesn’t rule this out. Whether the check blocks a request depends on whether the client has the __test cookie, so a request from a client that already passed the check can get through.