React连接到无端点的API



reactjs的新事物,我想将React App与Nodejs API连接,生产构建托管在url/url/api/的API,如何在生产中使用API为/api,而开发中的url/apip>

设置apiendpoint获取窗口配置并检查主机名。

我所做的是,如果它不是现场URL将其视为开发的NAD生产,否则

let apiEndpoint;
const hostname = window && window.location && window.location.hostname;
console.log("hostname", hostname);
if (hostname !== 'url.com')
    apiEndPoint = "https://url.com/api";
else
    apiEndPoint = '/api';

console.log(apiEndPoint);

最新更新