Closed evdama closed 5 years ago
Thanks for raising this issue. I don't have the time to investigate right now but I will do it at the beginning of the next week.
I was able to reproduce and fix the issue.
The default Ipregistry bundle loaded by sapper on browsers does export Ipregistry classes, nor a default export. Only the ESM bundle does.
I have published a new version of the Ipregistry client library (1.2.1) and written a small working example with sapper:
https://github.com/ipregistry/ipregistry-sapper
The file that you are interested in is src/routes/ipregistry.svelte
:
brilliant, I'll test this tonight and report back here! Also, the fact that you addressed and fixed this issue in time assures me even more that I've landed on the right IP service with you guys... good stuff! :)
I posted your sapper example to https://discordapp.com/channels/457912077277855764/473466028106579978 for others to test and toy around with...
Your support and trust are really appreciated. Thanks!
so I've settled with this code which works just fine
import ipregistry from '@ipregistry/client'
export default async ( ipAddress, filters ) => {
try {
const client = new ipregistry.IpregistryClient('ROLLUP_IPREGISTRY_KEY', new ipregistry.DefaultCache(16384))
return await client.lookup(ipAddress,
ipregistry.IpregistryOptions.hostname(true),
ipregistry.IpregistryOptions.filter(filters))
} catch ( error ) {
console.log( 'IPRegistry error code: ' + error.code )
console.log( 'IPRegistry error message: ' + error.message )
console.log( 'IPRegistry error resolution: ' + error.resolution )
}
}
two more things
user-agent
header from the HTTP request yes? then use it with this function yes? can you maybe point me in the right direction?I was thinking about using https://www.npmjs.com/package/express-useragent in order to get the user-agent information, then put it inside an express session variable because that's the place where I make the call to IPRegistry as well (every session/visitor gets his IP evaluation). Makes sense?
Thanks for your feedback.
I don't know where you call the functions above but be careful. As you know, with Sapper, the same code may be called on server-side and client-side depending on where you put it. This means that you might need to check if the window
variable is defined to detect the environment and adapt how the user-agent is retrieved:
req.headers['user-agent']
on server-side with expressjs, or
navigator.userAgent
on client-side.
Please create a separate issue if you encounter any problems.
I'm using Sapper which does server side rendering. There I have code calling the IPRegistry API using the javascript library of yours:
Because with sapper you do SSR, then ship the page down to the client, den hydrate it you've to basically take care of server and client when importing. Other ES6 imports work fine, but using
/@ipregistry/client
I get this error in the consoleNote that a native axios version works just fine. This is what I had before: