pikax / swgoh

Unofficial node library for swgoh.gg
MIT License
17 stars 4 forks source link

Possible CORS problem? #7

Closed tlr3552 closed 6 years ago

tlr3552 commented 6 years ago

Using your starter code and my SWGOH credentials, I was unable to get my info from swgoh.gg. It seems like a CORS issue when trying to get "https://swgoh.gg/u//":

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Am I missing something completely or is there an issue with the swgoh.profile(username) function call somewhere?

Thanks!

pikax commented 6 years ago

The login functionality is only needed for getting info of your profile character (eg: https://swgoh.gg/u/{username}/collection/238/commander-luke-skywalker/), that's is not yet supported, is something I'm working on.

swgoh.login("pikax", "{xxxx}")
    .then(x=>swgoh.profile("pikax"))
    .then(console.log);

output

{ galacticPower: 2530941,
  charactersGalacticPower: 1570397,
  shipsGalacticPower: 960544,
  pVEBattlesWon: 57679,
  pVEHardBattlesWon: 14655,
  galacticWarBattlesWon: 6178,
  arenaBattlesWon: 2173,
  guildCurrencyEarned: 533213,
  raidsWon: 406,
  shipBattlesWon: 305,
  collectionScore: 56.38,
  characters: 145,
  characters7: 113,
  characters6: 8,
  gearXII: 10,
  gearXI: 15,
  gearX: 7,
  gearIX: 12,
  gearVIII: 44,
  username: 'pikax',
  userId: 17421,
  arenaRank: 36,
  level: 85,
  allyCode: '495-616-697',
  joined: 'Aug 09, 2016',
  guild: 'Requiem',
  guildUrl: '/g/232/requiem/',
  lastUpdatedUTC: '2018-05-11T18:02:52Z' }

Am I missing something completely or is there an issue with the swgoh.profile(username) function call somewhere?

Tests are passing, I can't reproduce it.

I ran profile against my guild with no errors:

swgoh.guild('/g/232/requiem/')
    .then(x => x.map(x => swgoh.profile(x.username)))
    .then(x=>Promise.all(x))
    .then(console.log);

can you provide more information?

tlr3552 commented 6 years ago

I seem to have figured it out. Thanks for your response!