Configure the URL
Learn how to configure your public website URL, server listening address, and reverse proxy settings.
Overview
Configuring your application's URLs correctly is vital for generating working links, handling redirects, and ensuring your server is accessible over the network.
In this guide, you will learn how to:
- Set the Public URL (what users see).
- Configure the Listening URL (where the server binds).
- Use environment variables and
.envfiles. - Set up JopiJS behind a Reverse Proxy.
1. The Public URL (JOPI_WEBSITE_URL)
The Public URL is the address users type in their browser (e.g., https://example.com). JopiJS uses this URL to generate absolute links, handle SEO tags, and manage redirects.
Recommended: Environment Variables
Using environment variables is the most flexible way to configure your project, especially for Docker or CI/CD pipelines.
Using DotEnv files:
JopiJS automatically loads .env files based on your environment:
| File | Usage |
|---|---|
.env | Loaded in all environments. |
.env.development | Loaded only in development mode. |
.env.production | Loaded only in production mode. |
# The public address of your website
JOPI_WEBSITE_URL=https://my-great-website.comAlternative: package.json
You can also set a default URL directly in your package.json.
{
"jopi": {
"webSiteUrl": "http://localhost:3000"
}
}Priority: Environment variables always take priority over values defined in package.json.
2. The Listening URL (JOPI_WEBSITE_LISTENING_URL)
The Listening URL defines the internal IP and port where the JopiJS server binds.
- Default: value of JOPI_WEBSITE_URL.
- Listening network:
http://0.0.0.0:3000(Listens on all network interfaces on port 3000). - Listening local only: Typically
http://127.0.0.1:3000.
# Forces the server to listen only on localhost, port 8080
JOPI_WEBSITE_LISTENING_URL=http://127.0.0.1:80803. Using a Reverse Proxy
In a production environment, you rarely expose your Node.js/Bun server directly to the internet. Instead, you use a Reverse Proxy like Nginx, Apache, or Caddy.
Internal vs. Public URLs
When using a proxy, you must distinguish between your internal and public addresses:
| Type | Variable | Example |
|---|---|---|
| Public URL | JOPI_WEBSITE_URL | https://my-site.com |
| Internal URL | JOPI_WEBSITE_LISTENING_URL | http://127.0.0.1:3000 |
How it works:
- A user visits
https://my-site.com. - The Reverse Proxy (Nginx) receives the request.
- The Proxy "forwards" the request internally to
http://127.0.0.1:3000. - JopiJS processes the request and sends the response back to the Proxy.
Pro Tip: Your reverse proxy usually handles SSL/HTTPS termination. This means JopiJS can run internally on HTTP (http://127.0.0.1:3000), while the outside world sees a secure https:// connection.