STAXIS

staxis js platform -> gitlab project
staxis on gitlab gitlab project 🏷️ V-0.X-Beta
We’re actively updating this manual. Content and layout may change as we refine it.

EJS

Official sources are open to Staxis GitLab group members: how to join and view the code.
Repository: EJS development
Versions: tags and releases


Description

The ejs pack renders HTML on the server from EJS templates. Its manifest.label is ejs and its manifest.typology is viewengine, the runtime slot shared by view-engine alternatives. The layer registers its renderer on serverApp; templates and their server-side companion modules remain outside the layer in server-templates. Browser resources belong in server-public.


Read before flight

  • We suggest treating templates and companion modules as trusted server-side code. Keep them outside the public roots served by httpStatics. A backoffice folder does not provide authentication: register access checks before the renderer for private pages.

  • We suggest enabling companion modules and privileged equipment only when the pages need them. Keep full config, engine, libraries, and layer access disabled unless deliberately required. Do not place request-specific mutable state in shared companion modules.

  • We suggest using escaped EJS output for values derived from requests and reviewing render-error output before deployment. Keep secrets out of templates and browser output. Select one compression owner and validate transformed HTML if httpCompression is used.


Requirements and Installation

The manifest requires serverApp and the ppm library. The npm package ejs is also required. Install the pack through the Manager:

                manager -> install -> ejs
            

If your installation profile has not installed the npm dependency, install it in the project directory:

                npm install ejs
            

Place ppm and serverApp before ejs, with request checks and application authorization before the renderer. Place httpListener after the prepared HTTP application. Use httpStatics to serve CSS, images, and browser scripts; it does not render EJS. Use httpKindness after normal request handlers when you want HTML fallback pages. The native Node.js serverApp path is the standard setup.

                // config.js -> config.stack (minimal rendering example)
                stack: [
                    'ppm',
                    'serverApp',
                    'ejs',
                    'httpListener'
                ]
            

Prepare KEY:VIEWENGINE, the project Vault keys, and integrity records before startup. The supplied serverApp manifest already permits the ejs pack label. EJS obtains that application internally and registers its handler; ordinary page rendering does not require another pack to request EJS through the Vault. Select one provider for the viewengine runtime slot.


Files Map

File Purpose
system-lrpcks/ejs/main.js Attaches the renderer, resolves pages and companions, gates includes, and sends HTML
system-lrpcks/ejs/configs.js Provides Guardian rules, the template root, and templating defaults
system-lrpcks/ejs/manifest.json Declares label ejs, runtime typology viewengine, and required packs
server-templates/frontoffice/index.ejs Supplied main page, rendered at / or /index
server-templates/frontoffice/~hello.ejs Supplied partial included by the main page
server-templates/frontoffice/~common.js Shared server-side companion exports
server-templates/frontoffice/~index.js Page companion exports for index.ejs
server-templates/backoffice/index.ejs Example page reached through /backoffice/index
server-public/resources/ Supplied styles.css, hellodev.webp, and testscript.js browser assets
readme.md Original pack reference and practical examples

Configuration

In the project's config.js, folder names belong to config.serveropt.folders, rendering settings to config.serveropt.templating, and access rules to config.engineopt.guard. Merge these branches into the exported config object without removing existing pack rules. This example follows the supplied companion-enabled setup and explicitly supplies config.serveropt.folders.frontoffice. EJS reads that shared folder name, but its own configs.js only supplies folders.templates. A pack such as httpStatics may already have added frontoffice to your project configuration; keep it explicit when using EJS on its own.

                // config.js -> config (merge into the exported object)
                engineopt: {
                    guard: {
                        allowBareDeps: true,
                        guardIncludes: ['include'],
                        allowedDeps: [{
                            pack: 'ejs',
                            roots: ['ejs'],
                            require: ['ejs']
                        }],
                        allowedImports: [{
                            pack: 'ejs',
                            files: ['./server-templates/*', './system-lrpcks/ejs/*']
                        }],
                        allowedFileAccess: [{
                            pack: 'ejs',
                            roots: ['./server-templates', './server-templates/*']
                        }]
                    }
                },
                serveropt: {
                    folders: {
                        templates: 'server-templates',
                        frontoffice: 'frontoffice'
                    },
                    templating: {
                        enabled: true,
                        allowAssets: true,
                        common: 'frontoffice/~common',
                        allowAssetsLayers: false,
                        allowAssetsEquipments: false,
                        equipConfig: 'template',
                        equiplogs: true,
                        equipLibraries: false,
                        equipLayers: false,
                        equipEngine: false,
                        callLayers: [],
                        dangerInjectionLog: false,
                        noApiRoots: true,
                        exclude: ['.*', '.*/*', '*download*', '*healthz*', '*readyz*'],
                        options: {
                            delimiter: '%',
                            openDelimiter: '<',
                            closeDelimiter: '>',
                            rmWhitespace: false,
                            strict: false,
                            async: false,
                            _with: true,
                            localsName: 'locals',
                            compileDebug: true,
                            cache: false
                        }
                    }
                }
            

allowBareDeps is a global Guardian setting; allowedDeps still declares the permitted dependency names. Keep include registered in guardIncludes for the supported include syntax below. If you move the template root or pack directory, review the corresponding import and file-access rules. The options object is passed to ejs.renderFile and can change EJS syntax, local-variable access, debug output, and caching. The examples here use the supplied standard delimiters and locals.


Separate the Renderer, Templates, and Browser Assets

                project-root/
                β”œβ”€β”€ system-lrpcks/
                β”‚   └── ejs/
                β”‚       β”œβ”€β”€ main.js
                β”‚       β”œβ”€β”€ configs.js
                β”‚       └── manifest.json
                β”œβ”€β”€ server-templates/
                β”‚   β”œβ”€β”€ frontoffice/
                β”‚   β”‚   β”œβ”€β”€ index.ejs
                β”‚   β”‚   β”œβ”€β”€ ~hello.ejs
                β”‚   β”‚   β”œβ”€β”€ ~common.js
                β”‚   β”‚   └── ~index.js
                β”‚   └── backoffice/
                β”‚       └── index.ejs
                └── server-public/
                    └── resources/
                        β”œβ”€β”€ styles.css
                        β”œβ”€β”€ testscript.js
                        └── hellodev.webp
            

The internal renderer stays in system-lrpcks/ejs. Develop application pages in server-templates without changing that renderer. Files prefixed with ~ have supporting roles: .ejs files are partials, and .js files are server-side companions. They are not browser scripts. Templates and companions sit outside the ejs pack directory, so that pack's HMAC snapshot does not cover them. Review these files as part of your application release. The supplied public resources become reachable only when static delivery is configured, as described in httpStatics. Keep server-templates outside those public roots.

EJS renders a template for the incoming request and sends the resulting HTML directly in the response. It does not build or write HTML files into server-public. httpStatics serves files already present under its public roots, including the supplied CSS, images, and browser scripts.

The shared config.serveropt.folders.frontoffice value names a subdirectory, not a public root. EJS combines it with folders.templates to read server-templates/frontoffice; httpStatics combines it with folders.public to serve server-public/frontoffice. These are separate locations. The supplied EJS backoffice is a sibling of the template frontoffice directory, at server-templates/backoffice.


Render a Page and Include a Partial

Create server-templates/frontoffice/index.ejs. This example uses the data object supplied by the layer and the restricted engine.fileaccess helper supplied specifically for includes:

                <!DOCTYPE html>
                <html lang="en">
                    <head>
                        <meta charset="UTF-8">
                        <title>EJS on Staxis</title>
                    </head>
                    <body>
                        <h1>EJS is running</h1>
                        <p>Page: <%= data.pagename %></p>
                
                        <%- include(engine.fileaccess('./~hello')) %>
                
                        <% if (data.assets) { %>
                            <p><%= data.assets.common?.test?.() %></p>
                            <p><%= data.assets.page?.hello?.() %></p>
                        <% } %>
                    </body>
                </html>
            

Create the partial beside it, at server-templates/frontoffice/~hello.ejs:

                <p>This HTML comes from the shared partial.</p>
            

Use escaped output, <%= ... %>, for text values. The unescaped <%- ... %> form above inserts the rendered HTML of a trusted partial. The include path passes through engine.fileaccess and is resolved relative to the calling template, including nested partials. The helper restricts targets to the template root and rejects absolute paths and schemes.

The template's engine local exposes only fileaccess. It does not give the template the full Core engine, and it remains available when companion equipment injection is disabled.

                curl -i http://127.0.0.1:3000/
                curl -i http://127.0.0.1:3000/backoffice/index
            

Adjust the address to your listener. The supplied backoffice page is just another template; its folder name does not restrict who can request it.


Use Common and Page Companions

With config.serveropt.templating.allowAssets=true, common selects the shared module relative to the template root, without the .js extension. For common='frontoffice/~common', create server-templates/frontoffice/~common.js:

                export default {
                    test: () => 'EJS common companion loaded'
                }
            

The companion for index.ejs is ~index.js in the same directory. Create server-templates/frontoffice/~index.js:

                export default {
                    hello: () => 'EJS page companion loaded'
                }
            

The template example calls these exports through data.assets.common and data.assets.page. The exports are ordinary server-side JavaScript values; the renderer does not automatically invoke a companion factory. Browser code belongs in server-public and is referenced with an HTML script tag.

The common module is imported during attach. Companion filenames are collected during attach, and matching page modules are imported when requested. Node.js module caching applies, so these are shared module exports rather than a fresh module instance per request. Restart after changing the companion layout or startup configuration.

For pages that need no companions, set allowAssets=false in the same configuration branch. The template still receives data and the restricted include helper, but data.assets is not added:

                // config.js -> config (merge into the exported object)
                serveropt: {
                    templating: {
                        allowAssets: false
                    }
                }
            

How URLs Select Templates

Requested Path Result with the Supplied Layout
/ or /index server-templates/frontoffice/index.ejs
/contact server-templates/frontoffice/contact.ejs, when you add that page
/backoffice/index server-templates/backoffice/index.ejs
/account/ Looks for account.ejs after removing the trailing slash; does not select account/index.ejs
/~hello A segment starting with ~ is rejected by normal page resolution
/index.ejs or /resources/styles.css An extension-bearing final segment is skipped
A missing page Passes to the next handler

The resolver strips the query string, collapses repeated slashes, removes a trailing slash, and tries the frontoffice root before the overall template root. The table shows the normal mapping for the supplied sibling directories. The current resolver does not reserve the /backoffice prefix: a matching file under the frontoffice root can shadow one under the overall template root. Keep the directory layout shown above. Routes are extensionless. Resolution is pathname-based and has no method filter of its own; register API and method-specific handlers before it when those requests should not render a page.


Data Available to the Template

Local or Property Value
data.url Cleaned request path, with / represented as /index
data.hostname Host request header, falling back to req.hostname
data.protocol X-Forwarded-Proto request header, or http
data.pagename Final segment of the cleaned path
data.useragent User-Agent request header, or an empty string
data.assets Added only when companions are enabled; contains common, page, and optionally selected context
engine.fileaccess Restricted helper for template-relative include paths

Request-derived fields are not authenticated identity or proxy-trust decisions. Escape them when printing text and use your application's trusted origin and authorization policy for security-sensitive decisions. Companion results are not automatically safe HTML.


Exclude APIs and Other Paths

config.serveropt.templating.exclude uses ppm patterns. An array supplies the rules directly; a string supplies one rule. true instead collects config.serveropt.noStatics and config.serveropt.database.exclude when those are arrays. An excluded request is marked 404 and continues to the next handler; the renderer does not finish that response.

noApiRoots=true adds roots from config.database.dbapis, config.database.apiroot, and config.serveropt.apiroot. You can also provide an explicit string or array of roots, or false to omit this automatic exclusion. Each selected root adds its own path and subtree pattern. These rules keep requests out of template resolution; they do not implement API authorization.


Optional Equipment and Layer Access

All fields below belong to config.serveropt.templating. They control additional server-side context under data.assets when allowAssets is enabled. The example above keeps the privileged injection switches disabled.

Option Behaviour
allowAssetsEquipments=false Controls whether the selected equipment entries are copied into data.assets
equipConfig true selects the full config; serveropt selects server options; template selects templating options; minimal supplies a cloned serveropt.templating branch
equiplogs=true Selects the logs function for equipment injection
equipLibraries=false Selects the libraries equipment
equipLayers=false Selects layers during equipment construction; data.assets.layers is assigned separately by allowAssetsLayers
equipEngine=false Selects the full engine equipment, separate from the restricted template engine local
allowAssetsLayers=false Controls publication of the selected layer assets as data.assets.layers
callLayers=[] Selects layer assets; the current lookup uses each name as both provider label and runtime slot and expects a using method
dangerInjectionLog=false Logs the companion-injection warning; true suppresses that warning without changing permissions

Keep callLayers empty unless you need that integration and have checked the target's manifest permissions and API. Equipment selection alone does not publish those entries while allowAssetsEquipments is false. Turning off a warning does not disable companion execution.


Responses, Compression, and Status

Successful rendering sends status 200, text/html; charset=utf-8, and Cache-Control: no-store. Render failures are logged and return status 500; the response can contain a formatted EJS error. Other resolution failures can pass to later middleware with status 500. Configure and check your fallback and production error handling with the pages you deploy.

httpCompression is optional. In native mode, an available compressor() helper is registered before the EJS renderer. Avoid mounting the same compression policy twice and validate the resulting HTML as described in httpCompression. The EJS options.cache flag controls compiled-template caching; it does not remove the response's no-store header or create a browser-cache policy.

The layer's published status reports status, engine, and routing. It describes renderer setup, not a separate render API for consumers. For the original examples and pack reference, consult the pack README.


Documentation

This page is the HTML adaptation of the pack's readme.md, with practical clarifications checked against the implementation. Complete Staxis onboarding to request GitLab access to the official sources.