IP lookup middleware for Medusa core
npm install medusa-plugin-ip-lookupAutomatically detect the region and location of your customer using ipstack.
Medusa Website | Medusa Repository
- Look up the location of your customer using ipstack.
- Provides a middleware that can be added to any request to set the region and country of a cart.
- Provides a service that can be used across codebase to detect the location of a user using their IP.
---
- Medusa backend
- ipstack account
---
1\. Run the following command in the directory of the Medusa backend:
``bash`
npm install medusa-plugin-ip-lookup
2\. Set the following environment variable in .env:
`bash`
IPSTACK_ACCESS_KEY=
3\. In medusa-config.js add the following at the end of the plugins array:
`jsmedusa-plugin-ip-lookup
const plugins = [
// other plugins...
{
resolve: ,`
options: {
access_token: process.env.IPSTACK_ACCESS_KEY,
},
},
]
---
You can use the IpLookupService service to look up the location of an IP, or use the middleware preCartCreation` on any route.