Explita InfraExplita Infra
Tunnel

Multi-Tenant SaaS Routing

Test multi-tenant SaaS applications, custom subdomains, and workspace routing using Explita Tunnel's double-hyphen syntax

Modern SaaS applications—such as Slack, Jira, Shopify app ecosystems, and enterprise multi-tenant portals—often partition customer workspaces by subdomain:

  • https://acme.yourapp.com
  • https://stark-industries.yourapp.com
  • https://wayne-enterprises.yourapp.com

Testing this locally with standard tunneling tools is notoriously difficult due to DNS and TLS certificate limitations.


🚫 The Wildcard TLS Limitation

Standard wildcard TLS certificates (e.g. *.tunnel.explita.ng) issued by Let's Encrypt only validate a single DNS label level:

HostnameValid under *.tunnel.explita.ng?Reason
myapp.tunnel.explita.ng✅ YesSingle level matches *
acme.myapp.tunnel.explita.ng❌ No (TLS Handshake Error)Two levels (acme.myapp) cannot match single wildcard *

Issuing nested multi-level wildcard certificates requires complex DNS automation, rate limits, and custom edge routing.


💡 The Solution: Double Hyphen (--) Delimiter

Explita Tunnel solves this elegantly with the double hyphen (--) syntax:

https://{tenant}--{parentSubdomain}.tunnel.explita.ng

Because acme--myapp contains only hyphens, it forms a single DNS label that is 100% valid under standard single-level *.tunnel.explita.ng wildcard certificates.

How It Works in Practice

  1. Start your local tunnel with a base subdomain:
    eta 3000 -s myapp
  2. Your base tunnel is live at https://myapp.tunnel.explita.ng.
  3. Now send requests to any arbitrary tenant prefix using --:
    curl https://acme--myapp.tunnel.explita.ng/api/workspace
    curl https://nike--myapp.tunnel.explita.ng/dashboard
    curl https://stripe--myapp.tunnel.explita.ng/webhook
  4. The gateway identifies myapp as the active tunnel owner, routes the request across your existing connection, and injects tenant contextual headers.

📨 Injected Explita Headers

When a multi-tenant request reaches your local application, the gateway extracts and provides parsed metadata headers:

HeaderExample ValueDescription
x-explita-tunnel"true"Confirms request arrived via Explita Tunnel
x-explita-subdomain"acme--myapp"The full subdomain requested by the client
x-explita-parent-subdomain"myapp"The registered base subdomain of the tunnel
x-explita-tenant"acme"The extracted tenant workspace identifier
x-explita-subdomain-prefix"acme"Same as tenant identifier
x-explita-subdomain-parts"acme"Comma-separated list if nested prefixes are supplied
x-explita-client-ip"203.0.113.19"Verified public IP address of the caller
x-explita-request-id"<uuid>"Unique trace ID for the request

[!NOTE] All incoming caller headers starting with x-explita-* are strictly stripped at the gateway before routing. An external attacker cannot spoof tenant IDs or inject malicious values into these headers.


💻 Framework Integration Examples

Next.js (App Router Middleware)

In your middleware.ts:

import { NextResponse, type NextRequest } from "next/server";

export function middleware(req: NextRequest) {
  const url = req.nextUrl;
  const hostname = req.headers.get("host") || "";

  // 1. Check for Explita Tunnel tenant header (local dev)
  let tenant = req.headers.get("x-explita-tenant");

  // 2. Production fallback: parse tenant from production host (e.g. acme.yourapp.com)
  if (!tenant && hostname.includes(".yourapp.com")) {
    tenant = hostname.split(".")[0];
  }

  if (tenant) {
    // Rewrite path to tenant workspace route
    url.pathname = `/workspaces/${tenant}${url.pathname}`;
    return NextResponse.rewrite(url);
  }

  return NextResponse.next();
}

Express.js

import express from "express";

const app = express();

app.use((req, res, next) => {
  // Check Explita Tunnel header or hostname
  const tenant = req.headers["x-explita-tenant"] || req.hostname.split(".")[0];

  req.tenant = tenant;
  next();
});

app.get("/dashboard", (req, res) => {
  res.json({
    message: `Welcome to workspace: ${req.tenant}`,
    tunnelRouted: req.headers["x-explita-tunnel"] === "true",
  });
});

app.listen(3000);

🧪 Testing Nested Multi-Level Prefixes

If your SaaS platform organizes hierarchies (e.g. region and customer like eu.acme.yourapp.com), you can chain double hyphens:

curl https://eu--acme--myapp.tunnel.explita.ng

The gateway parses this and populates:

  • x-explita-tenant: "eu--acme"
  • x-explita-subdomain-parts: "eu,acme"

Your application can split on commas to resolve the entire tenant hierarchy instantly.

On this page