Hello, im hosting my express server on render and im facing an issue.
“Access to XMLHttpRequest at ‘https://raftech.adaptable.app/summoner/euw/kaleka’ from origin ‘https://www.rafte.ch’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”
this problem doesnt occur on my local machine
and im unable to resolve it on my own
const express = require("express");
const axios = require("axios");
const cors = require("cors");
require("dotenv").config();
const app = express();
const PORT = process.env.PORT || 8000;
app.use(cors());
app.get('/summoner/:region/:summonerName/live',cors() ,async (req, res) => {
try {
const { region, summonerName } = req.params;
const { apiRegion } = regions[region] || { apiRegion: region };
const { data: { id: summonerId } } = await axios.get(`https://${apiRegion}.api.riotgames.com/lol/summoner/v4/summoners/by-name/${summonerName}?api_key=${process.env.RIOT_API_KEY}`);
const { data: liveResponse } = await axios.get(`https://${apiRegion}.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/${summonerId}?api_key=${process.env.RIOT_API_KEY}`);
const ranks = await Promise.all(
liveResponse.participants.map(async (participant) => {
const { data: livePartic } = await axios.get(`https://${apiRegion}.api.riotgames.com/lol/league/v4/entries/by-summoner/${participant.summonerId}?api_key=${process.env.RIOT_API_KEY}`);
return livePartic.filter(entry => entry.queueType === 'RANKED_SOLO_5x5');
})
);
res.status(200).json([liveResponse, ranks]);
} catch (error) {
console.error(error);
if (error.response && error.response.status === 404) {
console.log("No live game found");
res.json(null);
} else {
res.status(500).json({ error: "Internal server error" });
}
}
});
i pasted part of my code above, please help me