Skip to content

Client - serving content

jetQuery serves the browser UI itself: static files (css, js, images, fonts, html pages) and the index - the single HTML page (SPA shell) that loads the UI. Files come from system files (the server www folder) and from client applications. The index is built from www/index.html and, for signed-in users, can be replaced by their own application's pages/index.html.

Terms used on this page:

  • System files - the server www folder (internal app name aaa-server).
  • Client application - an application with app_client = true (marked as UI). Its files are served and its components are bundled into the index. Set with POST /api/core/apps/update/{app_name} (app_administrator), see Apps.
  • User app context - the application selected by the signed-in user (user_app_name), set with POST /api/core/account/context/{app_name}, see Account.

Request lifecycle

Every request goes through the same steps:

  1. Block list - a request whose path matches blocked-url.txt (e.g. .php, /.env, /wp-admin) adds the client IP to blocked-ip.txt for 15 minutes; blocked IPs get 404 for every request.
  2. Tenant - the tenant is resolved from the Host header; an unknown domain is rejected.
  3. Authentication - the user is identified, when present, from the ptoken cookie, Authorization: Bearer|Token|Basic, or ?ptoken=api:{token} (which also sets the ptoken cookie). Content routes are anonymous - authentication only changes which index is returned.
  4. Routing - the path selects one of the handlers below.
Path Result
/api/... API endpoint, unknown endpoint → 404
/assets/..., /components/..., /js/..., /css/..., /images/..., /p/..., /favicon.ico, /favicon.png Static file
/pages/... Page - static file with fallback to the index
/robots.txt, /sw.js file from system files, 404 if missing
/manifest.json manifest.json from the server folder, or a default manifest
any other path without extension, e.g. /, /srs/124, /login Index
any other path with an extension, e.g. /test.png 404 (exception: paths containing @, e.g. /recover/{uuid}/{email})

Static files

HTTP
GET {{host}}/css/site.css

Resolution - first match wins:

  1. Client applications, in alphabetical order of app_name: {app folder}/css/site.css.
  2. System files: www/css/site.css.
  3. Not found → 404.

Rules:

  • Only these extensions are served, other extensions → 403: .css, .html, .js, .mjs, .cjs, .ts, .mts, .cts, .pdf, .json, .ico, .woff, .woff2, .ttf, .otf, .jpg, .jpeg, .png, .svg, .webp, .gif, .mp4
  • The file is served exactly as requested - there is no automatic .min lookup. Minified versions are used only when the index is built, see Building the index.
  • ?app_name={app_name} looks only in that client application, then in system files; ?app_name=aaa-server reads only from system files. The index uses this for linked components.
  • A path that resolves outside the application or www folder, or contains \, → 404.
  • Responses carry an ETag (last write time + size); a matching If-None-Match returns 304.

Pages

/pages/ works like static files, plus clean URLs and a fallback to the index:

Request Tried in order (first match wins)
/pages/test.html pages/test.html → index
/pages/test pages/test.html → pages/test/index.html → index
/pages/test.js (any other extension) pages/test.js → 404

Each candidate file is resolved like a static file (client applications, then system files). A trailing slash is ignored: /pages/test/ is the same as /pages/test.

Index

The index is returned for every route of the UI. Which index depends on the user - first match wins:

User Index
anonymous server index
signed in pages/index.html of the user app context → server index

The user app index is used only when all of these are true:

  • the user has an app context (user_app_name),
  • the user has role app_{app_name} or app_administrator,
  • the request comes from an address allowed by the application app_locations,
  • the file {app folder}/pages/index.html exists.

How the user app index is served:

  • File contains content="jetQuery.io" (exact text, case-sensitive, normally in <meta name="generator" content="jetQuery.io" />) → it is a template, built like the server index, see Building the index.
  • Otherwise → the file is returned as is, no tokens are replaced.

Warning

pages/index.html replaces the whole UI for every user of the application. Anyone with app_{app_name}_write can change it (storage save/upload), so treat this role as able to run JavaScript in the browsers of all users of the application.

Note

A broken user app index cannot be bypassed with a query parameter (?paanda=recovery was removed). Fix the file, change the user app context (POST /api/core/account/context/{app_name}), or delete pages/index.html.

Example

HTTP
GET {{host}}/srs/124
Cookie: ptoken={{jwt}}
  1. /srs/124 has no extension → index.
  2. The user is signed in with app context erp and has role app_erp → {datastore}/apps/erp/pages/index.html exists → it contains content="jetQuery.io" → the built template is returned.
  3. The same request without the cookie returns the server index.

Building the index

The server index is built from www/index.html. A user app template is built the same way - only the HTML shell differs.

  1. Collect components from system files and from every client application:

    Folder Type Priority
    /js/ .js 10
    /components/ .js 20
    /pages/ .js 33
    /css/ .css 100

    Subfolders are included. Only .js and .css files are bundled - .html files are never bundled.

  2. Remove duplicates - one component per file name (e.g. v_home.js), the first one in this order wins: 1. lower priority number, 2. relative path, alphabetically (/components/system/v_home.js before /components/v_home.js), 3. for the same relative path - application name in reverse alphabetical order, so a client application overrides a system file with the same path.

  3. Validate - a .js file outside /js/ must have a valid JavaScript function name (0-9a-zA-Z_), otherwise it is skipped and a warning is written to the browser console.
  4. Minify or link: - name.min.js / name.min.css next to name.js / name.css → the .min file is used as is, - file smaller than jetquery_server_bundle_size (default 150000 bytes) → minified and inlined in the page, - larger file → linked: <script src="{host}/components/v_big.js?t={modified}&app_name={app}">.
  5. Place - .js with !body in the path → @paanda_body, other .js → @paanda_head, .css → @css_init.
  6. Replace tokens in the template:
    Token Value
    @css_init css components
    @paanda_head js components (place in <head>)
    @paanda_body !body js components (place at the end of <body>)
    @paanda_warnings console warnings, empty if none
    @variables.settings.system.version server version
    @template_time, @template_date build time in ms, build date (UTC)
    @time_token time of the last application settings change (apps/update)
    @apiurl, @hosting_domain {scheme}://{host} of the request, e.g. https://app.example.com

Minimal template, e.g. {app folder}/pages/index.html:

HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="jetQuery.io" />
  @css_init
  @paanda_head
</head>
<body>
  <div id="vue" v-cloak><router-view></router-view></div>
  <script>window.apiurl = '@apiurl'; window.version = '@variables.settings.system.version';</script>
  @paanda_body
  @paanda_warnings
</body>
</html>

Note

Avoid the same file path in two client applications. Static files take the first application in alphabetical order, the index build takes the last one.

Caching and refresh

The built index is kept in server memory per tenant and per scheme (http / https), so a request only returns the cached page.

The index (server index and all user app templates) is rebuilt on the next request after:

  • POST /api/core/apps/create|update|scm-pull|scm-reset/{app_name}
  • POST /api/core/storage/upload|save|delete|scm-checkout/{app_name}/...
  • server restart

A user app template is also rebuilt when the file pages/index.html changes (last write time or size).

Warning

Files changed directly on disk (copy, git pull outside the API) are not picked up until one of the calls above or a restart. Static files are always read from disk.

If the build fails, e.g. the database is not reachable, the page shows the error and is not cached - the next request tries again.

HTTP caching:

  • Index: ETag + Cache-Control: private, no-cache - the browser revalidates every time (304 when unchanged); the same URL returns different content for different users, so shared caches (proxy, CDN) must not store it.
  • Static files: ETag only.

Local development

POST /api/core/dev/client-index builds the index with local component files instead of the server ones, see DevOPS Automation.

Application directory structure

example:

  • /components - components, bundled into the index (.js)
  • /pages - pages: .js bundled into the index, .html served on /pages/..., pages/index.html - optional user app index
  • /js - javascript, bundled into the index
  • /css - client css, bundled into the index
  • /srs - api definition files, not served as files
  • /templates - templates (svg, mail), not served as files

Folders /components, /pages, /js, /css are used only when the application is a client application (app_client = true), except pages/index.html, which is used for the user app context.