# How to use Upstash GeoLocation through Azion

import Tag from '~/components/webkit/Tag.vue';

<Tag severity="info">
Preview
</Tag>

**Upstash GeoLocation** is an automation designed to deploy a database directly on the edge while enabling the configuration of custom messages that will be delivered according to the user's geographical location.

These messages are delivered through a static interface, based on HTML and generated by the template after deployment.

---

## Requirements

Before using this template, you need to:

- Create an [Upstash account](https://console.upstash.com/).
- Create a Global Database for the best available edge latency in the [Upstash Console](https://console.upstash.com/).
- Have a [GitHub account](https://github.com/signup) to connect with Azion and create your new repository.
  - Every push will be deployed automatically to this repository to keep your project updated.
- This template uses [Application Accelerator](/en/documentation/products/build/applications/application-accelerator/) and [Functions](/en/documentation/products/build/applications/functions/), and it may generate usage-related costs. Check the [pricing page](https://www.azion.com/en/pricing/) for more information.

:::caution[Warning]
Any cost generated by Upstash usage will be processed and billed separately on the Upstash platform. Visit the [Upstash documentation](https://docs.upstash.com/redis/features/globaldatabase#pricing) for more details. 
:::

---

## Deploying the template

You can obtain and configure your template through the Azion Console. To easily deploy it at the edge, click the button below.

<DocButton
    label="Deploy"
    href="https://console.azion.com/create/upstash/upstash-geolocation"
    icon="ai ai-azion"
    size="medium"
/>

---

## Setting up the template

In the configuration form, you must provide the information to configure your Azion application. Fill in the presented fields.

1. Connect Azion with your GitHub account.
- A pop-up window will open to confirm the installation of the [Azion GitHub App](https://www.azion.com/en/documentation/products/guides/azion-github-app/), a tool that connects your GitHub account with Azion's platform.
- Define your permissions and repository access as desired.
2. Select the **Git Scope** to work with.
3. Define a name for your application.
- The bucket for storage and the function will use the same name.
- Use a unique and easy-to-remember name. If the name has already been used, the platform returns an error message.
4. Enter the following information:
- **Upstash Redis Rest URL** *: the URL to access your Upstash database using REST.
  - Go to your Upstash Console and copy the `UPSTASH_REDIS_REST_URL` in your database page.
- **Upstash Redis Rest Token** *: the token to authorize access to your Upstash database using REST. 
  - Go to your Upstash Console and copy the `UPSTASH_REDIS_REST_TOKEN` in your database page.
5. Click the **Deploy** button to start the deployment process.

During the deployment, you'll be able to follow the process through a window showing the logs. When it's complete, the page shows information about the application and some options to continue your journey.

:::note
The link to the application allows you to see it on the browser. However, it takes a certain time to propagate and configure the application in Azion's edge locations. It may be necessary to wait a few minutes for the URL to be activated and for the application page to be effectively displayed in the browser.
:::

### Key configurations

Upstash GeoLocation creates a new Azion application and its domain. It also creates an function to provide the arguments for the geolocation, a new repository in your GitHub account based on a [public template](https://github.com/aziontech/azion-samples/tree/dev/templates/upstash-geolocation), including a GitHub Action to enable continuous deployment, and a static interface to show the messages.

In this function, the `upstash/redis` library is integrated, connecting to your Upstash Global Database and retrieving the message based on the user's location. This location is taken from the metadata `["geoip_country_code"]`.

The template also incorporates location-based greetings in your database, which are retrieved from the integration with Upstash, similar to this:

```bash
Welcome to Upstash CLI

set BR "Olá, tudo bem!"
OK
set GB "Ey up?"
OK
set US "Yo, what's up?"
OK
set IN "Namaste"
OK
```

You can customize these greetings on your Upstash database to attend to your necessities.

To know more on how to edit and customize your project's settings, go to the [Managing your project on Azion](#managing-your-project-on-azion) section.

---

## Managing your project on Azion

Considering that this initial setup may not be optimal for your specific application, all settings can be customized any time you need by using Azion Console. Once the template is deployed, you also have full control over customizing your Upstash account and database.

To manage and edit your application's settings, follow these steps:

1. [Access Console](https://console.azion.com).
2. On the upper-left corner, select **Products menu** > **Applications**.
- You'll be redirected to the **Applications** page. It lists all the applications you've created.
3. Find the application related to the **Upstash GeoLocation** template and select it. 
- The list is organized alphabetically. You can also use the **search bar** located in the upper-left corner of the list; currently, it filters only by **Application Name**.

After selecting the application you'll work on, you'll be directed to a page containing all the settings you can configure.

:::tip
Read the documentation about [managing applications](/en/documentation/products/build/applications/first-steps/) for more details. For specific Upstash-related questions, check the [Upstash documentation](https://docs.upstash.com/).
:::

### Adding a custom domain

The application created during the deployment has an assigned Azion Workload domain to make it accessible through the browser. The domain has the following format: `xxxxxxxxxx.map.azionedge.net`. However, you can add a custom domain for users to access your application through it.

import DocButton from '~/components/webkit/DocButton.vue';

<DocButton href="/en/documentation/products/guides/configure-a-domain/" label="go to configuring a domain guide" kind="secondary" size="medium" />