IP Lookup (ipstack) Plugin
In this document, you’ll learn how to install the IP Lookup plugin on your Medusa backend.
Overview
Location detection in a commerce store is essential for multi-region support. Medusa provides an IP Lookup plugin that integrates the backend with ipstack to allow you to detect a customer’s location and, ultimately, their region.
This guide explains how you can install and use this plugin.
Prerequisites
Medusa Backend
Before you follow this guide, you must have a Medusa backend installed. If not, you can follow the quickstart guide to learn how to do it.
ipstack Account
You need an ipstack account before using this plugin. You can create a free account with ipstack on their website.
Install Plugin
In the root directory of your Medusa backend, run the following command to install the IP Lookup plugin:
Then, add the following environment variable in .env
:
Where <YOUR_ACCESS_KEY>
is your ipstack account’s access key. It’s available in your ipstack dashboard.
Finally, add the IP lookup plugin into the plugins array exported as part of the Medusa configuration in medusa-config.js
:
Test the Plugin
The plugin provides two resources: the IpLookupService
and the preCartCreation
middleware.
Due to how Express resolves the current IP when accessing your website from localhost
, you won’t be able to test the plugin locally. You can either use tools like ngrok to expose the 9000
port to be accessed publicly, or you have to test it on a deployed backend.