ga-wdi-boston / full-stack-project

Other
8 stars 64 forks source link

Can't access heroku app after updating API origin url #1023

Closed bradleyden closed 7 years ago

bradleyden commented 7 years ago

I had everything working how I wanted it between the two localhost links, so I pushed all my changes to my heroku app and updated the API origin url to test it.

Heroku url: https://guarded-fjord-43518.herokuapp.com/

When I try signing in from the localhost client, I get this error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7165' is therefore not allowed access. The response had HTTP status code 500.

const setAPIOrigin = (location, config) => {
  // strip the leading `'?'`
  const search = parseNestedQuery(location.search.slice(1))

  if (search.environment === 'development' ||
      location.hostname === 'localhost' &&
      search.environment !== 'production') {
    if (!(config.apiOrigin = config.apiOrigins.development)) {
      const port = +('GA'.split('').reduce((p, c) =>
        p + c.charCodeAt().toString(16), '')
      )
      config.apiOrigin = `https://guarded-fjord-43518.herokuapp.com`
    }
  } else {
    config.apiOrigin = config.apiOrigins.production
  }
}

module.exports = setAPIOrigin

I looked up the error and it seems to have to do with the fact that the request is coming from a different domain from the server, so should I add an Access Control Header to my API or did I do something else wrong somewhere?

Thanks!

cpearce31 commented 7 years ago

It might be more useful to deploy your front end and test the connection between the two deployed apps, instead of spending time troubleshooting the connection between localhost and Heroku.

bradleyden commented 7 years ago

Yes, I just realized that was the problem after looking at Parth's issue from before. I will do it that way and open a new issue if I still have issues. Thank you!