segler-alex / radiobrowser-api-rust

radio-browser API implementation in rust
GNU Affero General Public License v3.0
230 stars 96 forks source link

HTTPS for all.api.radio-browser.info #122

Closed abaldeweg closed 11 months ago

abaldeweg commented 3 years ago

The tls cert for https://all.api.radio-browser.info does not work for me on Chrome, stating Your connection is not private.

ivandotv commented 3 years ago

Actual error is net::ERR_CERT_COMMON_NAME_INVALID This makes the API unusable from the frontend (browser).

laravieira commented 1 year ago

To leave my experience, I needed HTTPS because my DNS has HSTS enabled, and disabling it is not an option.

This clearly is not a long-term fix, but I don't need that, so I overwrote the main class with: RadioBrowserApi.overwrite.ts

import {
  RadioBrowserApi as RadioBrowserApiSuper
} from 'radio-browser-api';
import https from 'https';
import axios from 'axios';

type Server = {
  ip: string,
  name: string
};

class RadioBrowserApi extends RadioBrowserApiSuper {
  constructor(appName: string, hideBroken = true) {
    super(appName, hideBroken);
  }

  // temporary fix for https cert error when in frontend hardcode the server
  // https://github.com/segler-alex/radiobrowser-api-rust/issues/122
  async resolveBaseUrl(config: RequestInit = {}): Promise<Server[]> {
    const httpsAgent = new https.Agent({

      rejectUnauthorized: false
    });
    const SERVER_LIST_URL = 'https://de1.api.radio-browser.info/json/servers';

    return axios(SERVER_LIST_URL, { httpsAgent })
      .then(response => response.status === 200 ? response.data : Promise.reject(response.status))
      .then(list => list as Server[])
  }
}

export default RadioBrowserApi;

What I basically did was change the subdomain from all to de1 since the certificate returned on all is for de1.