adobe / aem-sample-we-retail-journal

We.Retail Journal is a sample showcasing SPA Editing capabilities in AEM using React and Angular
Apache License 2.0
70 stars 69 forks source link

403 error with CustomModelClient #80

Closed R-Bower closed 4 years ago

R-Bower commented 4 years ago

I've done the following:

Issue: React app on localhost:9000 is just a black page, and the request to retrieve the model.json fails.

403 error on model client initialization: image

class CustomModelClient extends ModelClient {
  /**
   * Fetches a model using the given a resource path
   *
   * @param {string} modelPath - Path to the model
   * @return {*}
   */
  fetch(modelPath) {
    if (!modelPath) {
      return Promise.reject(
        new Error(`Fetching model rejected for path: ${modelPath}`)
      )
    }

    const url = `${process.env.API_HOST}${modelPath}`

    // Either the API host has been provided or we make an absolute request relative to the current host
    return fetch(url, {
      headers: {
        Authorization: `Basic ${Buffer.from("admin:admin").toString("base64")}`
      }
    }).then(function(response) {
      if (response.status >= 200 && response.status < 300) {
        return response.json()
      } else {
        const error = new Error(
          `while fetching the model for url: ${url}`,
          response.statusText || response.status
        )
        error.response = response

        return Promise.reject(error)
      }
    })
  }
}

Any ideas?

pfauchere commented 4 years ago

Aged ticket and lack of details and logs. Could be a CORS misconfiguration. Closing the issue for now. Feel free to reopen.