Can cors be enabled?

Hello, it’s me, again. I’m wanting to use a module that returns the names of the songs that are playing from a url, and with simple code it works, but when using it on the frontend I get a cors block. I tried to use npm cors but still can’t fix it. Can someone tell me how I can somehow enable the cors?
I leave here the code that I am using.

Here use browserify

const { Parser } = require('icecast-parser');

global.window.Parser = Parser;

Code in the html

const radioParser = window.Parser;
        const radioStation = new radioParser({ url: '' });
        radioStation.on('metadata', (metadata) => {

You need a backend for that, the code you are running was just not meant to run in the browser. If you can get a Node.js server you can run the code on that and send the metadata back to your frontend.

This endpoint seems to be sending metadata (including now playing) you can fetch from (in the browser).

For this station

Found on this page

It is hitting what I assume is not meant to be a public API endpoint so use it at your own risk. It might block you or change at any time.

You would also have to keep polling the endpoint to get the new track info unless you have some way of checking when the track changes. Make sure not to fetch from it more often than needed.

Well use the code I put above where start the server and with ejs send the result (which would be the name of the music)
The thing is, it works, but it doesn’t update.
With ejs use this

const { Parser } = require('icecast-parser");

let name;
const radioStation = new Parser({ url: '' });
   radioStation.on('metadata', (metadata) => {
   name = metadata.get('StreamTitle')

app.get("/", (req, res) => {
res.render("index", { song: name }); 

I’m sorry if I don’t quite understand what you’re explaining to me, I’m new to this backend: c

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.