node.jsapiexpressdnsurl-masking

redirect and masking a domain on a restful api


so I'm very new to node.js and back-end. I've just deployed a restful api on AWS just as a little test, it really does nothing special, only some get-post requests updating a json. It works as expected.

Problem is: the address is of course very long so i also wanted to redirect the requests from a domain easy to remember. And so i did. If the domain is unmasked, it works fine, and i can for example get a json: apiunmasked.pileoni.site/all Settings on namecheap: enter image description here

If i do try to mask it, it still works but the browser don't format it as a json: api.pileoni.site/all. enter image description here

Also there is something weird in the marging that happen with the masked version on the main page: api.pileoni.site apiunmasked.pileoni.site

I guess is some wrong setting on namecheap?

Thanks


Solution

  • Direct request to the EC2 do not adds the Content-Type header in HTTP response, so the browser tries to guess the datatype and correctly recognize and manages it as JSON. The Namecheap forward service adds the header, probably falling back to "text/html", and the browser display the content as HTML.

    Eventually, try to enforce the Content-Type header to "application/json" in your Node application with setHeader().