'Browser not using OPTIONS method when trying GET request (node.js http)

I was trying to write a basic SteamAPI application, but immediately got stuck with CORS. The browser is supposed to use OPTIONS method before using GET, which it for some reason doesn't.

Here's the index.js file:

const
http = require("http"),
fs = require("fs");

const
PORT = 7777,
APIKEY = fs.readFileSync("./steamapikey.txt", "utf-8"),
ID64 = fs.readFileSync("./steamid64.txt", "utf-8");

const server = http.createServer((req, res) => {

    console.log(req.method);

    if(req.method === "OPTIONS"){

        res.writeHead(200, {
            "Access-Control-Allow-Origin" : "*",
            "Access-Control-Allow-Methods" : "OPTIONS, POST, GET",
            "Access-Control-Allow-Headers" : "Origin, X-Requested-With, Content-Type, Accept"
        });
        
        return res.end();

    }

    res.writeHead(200, {"Content-Type" : "text/html"});
    res.write(`
<script>

let x = new XMLHttpRequest();
x.open("GET", "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${APIKEY}&steamids=${ID64}");
x.send(null);
console.log(x.response);

</script>
    `);
    res.end();

});

server.listen(PORT);

console.log(`Server listening on port ${PORT}`);

When I open the page, console logs "GET" twice, but not "OPTIONS". What am I doing wrong?

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source