|Manuals

Keeping WAG Sessions Active

A Web Application Gateway (WAG) instance stays active as long as it receives a keep-alive signal from the user’s browser. If the pages your site serves never carry the keep-alive script, the instance shuts down while users are still working. This page explains how the mechanism works and how to configure it for sites that need it.

How the Keep-Alive Works

When the WAG serves a document whose URL matches one of its template rules, it injects a small script block into the page. The injected thinfinity.wag.service.min.js script sends a ping every 30 seconds. If the WAG receives no ping — and no other endpoint request — for 45 seconds, it considers the session over and the instance shuts down.

Out of the box, the template rule matches documents ending in .html, .htm, .asp, or .aspx.

Document Matched by the default rule
page.html Yes
page.htm Yes
default.aspx Yes
script.asp Yes
file.json No
htmlfile No

If your site’s entry pages fall outside that rule — for example, a site built on PHP or JSP — no page carries the keep-alive script, and the WAG shuts down 45 seconds after serving it.

The wag-headers.json File

The injection is configured in the wag-headers.json file. It has two sections:

  • templates — named blocks of content to inject into the served documents.
  • template-by-url — regular expressions that decide which template applies to each document URL.

This is the base configuration:

{
    "templates": {
        "default": {
            "inject": [
                "<script>const brkUrl = '<%=BROKER_URL%>';</script>",
                "<script type='text/javascript'>const _thinfinity_wag_rule=<%=RULE_JSON%></script>",
                "<script src='<%=BROKER_URL%>thinfinity.wag.service.min.js' type='text/javascript'></script>"
            ]
        }
    },
    "template-by-url": {
        ".(html?|aspx?)$": "default"
    }
}

Thinfinity Workspace looks for wag-headers.json in two locations, in this order:

  1. The database folder of the installation — the Database path configured in your deployment.
  2. The installation folder.

The copy shipped with the product lives in the installation folder. When a copy exists in the database folder, it takes precedence.

Adding a Rule for Other Document Types

To keep sessions alive on a site whose documents don’t match the default rule, add a rule — reusing the default template or defining a new one. For example, to cover PHP and JSP documents:

{
    "templates": {
        "default": {
            "inject": [
                "<script>const brkUrl = '<%=BROKER_URL%>';</script>",
                "<script type='text/javascript'>const _thinfinity_wag_rule=<%=RULE_JSON%></script>",
                "<script src='<%=BROKER_URL%>thinfinity.wag.service.min.js' type='text/javascript'></script>"
            ]
        },
        "php": {
            "inject": [
                "<script>const brkUrl = '<%=BROKER_URL%>';</script>",
                "<script type='text/javascript'>const _thinfinity_wag_rule=<%=RULE_JSON%></script>",
                "<script src='<%=BROKER_URL%>thinfinity.wag.service.min.js' type='text/javascript'></script>"
            ]
        }
    },
    "template-by-url": {
        ".(html?|aspx?)$": "default",
        "\\.(php[3457]?|aspx?|jsp[x]?)(?=$|[?#])": "php"
    }
}

The added expression also matches URLs with query strings or fragments.

URL Matched by the added rule
login.php?ret=home Yes
view.aspx#section2 Yes
file.phpfoo No

Preserving Your Configuration

Warning

Updating or reinstalling Thinfinity Workspace overwrites the wag-headers.json in the installation folder. Keep a backup of your customized file, and place your copy in the database folder — that copy takes precedence and is not touched by updates.

Rules for a Specific Profile

Before falling back to the global wag-headers.json, the server looks for a rules file named after the profile’s subdomain — <subdomain>.wag, in the same two locations. Use it to apply injection rules to one Gateway-mode profile without affecting the rest.

Read more