> For the complete documentation index, see [llms.txt](https://kotus.gitbook.io/saas-starter-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kotus.gitbook.io/saas-starter-kit/helpers/geturl.md).

# getURL

## Description

The `getURL` function constructs a complete URL based on the provided path and environment variables. It ensures that the URL is correctly formatted and includes the appropriate protocol.

## Signature

```typescript
function getURL(path: string = ''): string;
```

## Parameters

* `path`: A string representing the path to append to the base URL. Defaults to an empty string.

## Example Usage

```typescript
import { getURL } from '@/src/lib/utils';
const fullURL = getURL('/dashboard');
console.log(fullURL); // Outputs the complete URL based on environment variables and the provided path.
```

## How It Works

1. **Environment Variables**: The function first checks if `NEXT_PUBLIC_SITE_URL` is set and non-empty. If so, it uses this value as the base URL.
2. **Vercel URL**: If `NEXT_PUBLIC_SITE_URL` is not set, it checks for `NEXT_PUBLIC_VERCEL_URL`, which is automatically set by Vercel.
3. **Localhost**: If neither environment variable is set, it defaults to `http://localhost:3000/` for local development.
4. **URL Formatting**: The function trims any trailing slashes from the base URL and ensures the URL includes `https://` when not localhost.
5. **Path Formatting**: The function ensures the provided path does not start with a slash to avoid double slashes in the final URL.
6. **Concatenation**: The base URL and the path are concatenated to form the complete URL.
