explodingcamera / subsonic-api

typescript/javascript library for interacting with subsonic-compatible apis
https://www.npmjs.com/package/subsonic-api
MIT License
13 stars 1 forks source link

Issue when importing package #1

Closed ChucKN0risK closed 1 year ago

ChucKN0risK commented 1 year ago

Hi @explodingcamera ✌️

After installing the package with npm in the following project I get the following error: CleanShot 2023-08-27 at 16 10 09

Did I miss something?

explodingcamera commented 1 year ago

Hi @ChucKN0risK, should be working now in v1.2.1 :+1:

explodingcamera commented 1 year ago

Seems like there were some issues with browser support for my dependencies, v1.3.2 is now working for me (the export is named SubsonicAPI, that used to be incorrect in the README)

explodingcamera commented 1 year ago

No worries! I fixed that error in v1.3.2, depending on your package manager, it might still have the old .1 version installed.

ChucKN0risK commented 1 year ago

Sorry for removing my previous messages. After trying several things they didn't seem to be relevant anymore. I've just updated to 1.3.2.

I'm running airsonic-advanced locally on localhost:4040 and I now have this issue: CleanShot 2023-08-27 at 21 21 54

I don't think it's related to your package though. Do you agree?

explodingcamera commented 1 year ago

Yes, I think you need to configure your local server to set the correct CORS headers, which are needed to interact with APIs on other domains (including other ports). I'm using this library with navidrome, which seems to allow CORS access.

ChucKN0risK commented 1 year ago

By using your example code based on navidrome I'm indeed able to receive 10 songs.

I tried the replacing the url and my credentials while using navidrome but it still shows the same issue.

const api = new SubsonicAPI({
  url: 'http://localhost:4040',
  type: 'navidrome', // or 'generic' or 'subsonic'
});

await api.login({
  username: 'admin',
  password: 'lucho',
});

const { randomSongs } = await api.getRandomSongs();
console.log(randomSongs);
explodingcamera commented 1 year ago

The demo server in the example replies to OPTIONS preflight requests and adds a cors header, you probably need to run your subsonic server through a reverse proxy and configure it to do this aswell, https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

ChucKN0risK commented 1 year ago

Thanks for your input. I'll check this out 🙏