googlecodelabs / your-first-pwapp

Code associated with Your First Progressive Web App codelab
https://g.co/codelabs/pwa
Apache License 2.0
637 stars 554 forks source link

Add mode: "no-cors" to fetch call. #195

Closed HunterHeston closed 3 years ago

HunterHeston commented 5 years ago

Users who download this repositories zip in step 1 of the your-first-pwapp guide will not fetch from Darksky's API. All fetches will result in this error Dark Sky API Error: Forbidden. Not an expert but the bellow should allow users to access Darksky data from localhost:8000

function getForecast(req, resp) {
  const location = req.params.location || '40.7720232,-73.9732319';
  const url = `${BASE_URL}/${API_KEY}/${location}`;
//  fetch(url).then((resp) => {
    fetch(url, {mode: 'no-cors').then((resp) => {
    if (resp.status !== 200) {
      throw new Error(resp.statusText);
    }
...