CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (push) Successful in 23s
CI / Test (jest) (push) Successful in 22s
CI / Security (npm audit) (push) Successful in 14s
CI / Scan (secrets, workflows, shell) (push) Failing after 18s
CI / Integration (api) (push) Successful in 2m43s
CI / Lint (eslint) (pull_request) Successful in 17s
CI / Test (jest) (pull_request) Successful in 18s
CI / Security (npm audit) (pull_request) Successful in 13s
CI / UI (playwright) (push) Successful in 3m0s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Scan (secrets, workflows, shell) (pull_request) Failing after 14s
CI / Integration (api) (pull_request) Successful in 2m24s
CI / UI (playwright) (pull_request) Successful in 2m16s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 2m18s
- eslint-plugin-security 4.2.1 (recommended-legacy) with detect-object-injection off (it flags every obj[key]) and file/regex rules off for CI scripts and tests. The remaining hits were false positives with a one-line reason each (fixed page names, the worker's own directory, a null check), plus one real tidy-up: the condition tokenizer's number regex is now two flat patterns with no backtracking, and malformed numbers like 1.2.3 are refused. - zizmor 1.32.0 in the Scan job. Its findings are fixed: persist-credentials: false on every checkout (no job pushes), container images pinned by digest (tag kept in the reference), and the deploy tag step takes github.* values through env instead of template expansion. Left as is: secrets-outside-env (auditor persona; Gitea has no deployment environments). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
3.3 KiB
JavaScript
102 lines
3.3 KiB
JavaScript
// Two-step EJS rendering: views/pages/<view>.ejs -> `body` -> views/layout.ejs.
|
|
// No express-ejs-layouts; the vendored layout is a wrapper file that expects `body`.
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const ejs = require('ejs');
|
|
const { navLinks } = require('./nav');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const VIEWS_DIR = path.join(ROOT, 'views');
|
|
const PAGES_DIR = path.join(VIEWS_DIR, 'pages');
|
|
const LAYOUT = path.join(VIEWS_DIR, 'layout.ejs');
|
|
const STUB = path.join(PAGES_DIR, '_stub.ejs');
|
|
|
|
const CACHE = process.env.NODE_ENV === 'production';
|
|
|
|
// Cache-busting token: <package version>-<web_template short sha>, computed once.
|
|
const assetVersion = (function computeAssetVersion() {
|
|
let version = '0.0.0';
|
|
try {
|
|
version = require(path.join(ROOT, 'package.json')).version || '0.0.0';
|
|
} catch (_) { /* keep default */ }
|
|
let sha = '';
|
|
try {
|
|
const raw = fs.readFileSync(path.join(ROOT, 'public/web_template/VERSION'), 'utf8').trim();
|
|
sha = (raw.split(/\s+/)[1] || '').trim();
|
|
} catch (_) { /* VERSION not vendored yet */ }
|
|
return sha ? `${version}-${sha}` : version;
|
|
})();
|
|
|
|
const APP_NAME = process.env.APP_NAME || 'PULSE';
|
|
const APP_SUBTITLE = process.env.APP_SUBTITLE || 'Worker Orchestration // LotusGuild';
|
|
|
|
function viewPath(view) {
|
|
const file = path.join(PAGES_DIR, `${view}.ejs`);
|
|
// eslint-disable-next-line security/detect-non-literal-fs-filename -- view names come from the fixed page list
|
|
return fs.existsSync(file) ? file : STUB;
|
|
}
|
|
|
|
// Render a page view inside the shared layout.
|
|
async function renderPage(req, res, view, locals = {}) {
|
|
const data = Object.assign({
|
|
user: req.user || null,
|
|
nonce: res.locals && res.locals.nonce,
|
|
appName: APP_NAME,
|
|
appSubtitle: APP_SUBTITLE,
|
|
csrfToken: '',
|
|
navLinks,
|
|
pageTitle: '',
|
|
activeNav: '',
|
|
pageStyles: [],
|
|
pageScripts: [],
|
|
pageConfig: {},
|
|
assetVersion
|
|
}, locals);
|
|
|
|
const opts = { cache: CACHE, filename: viewPath(view) };
|
|
const body = await ejs.renderFile(viewPath(view), data, opts);
|
|
const html = await ejs.renderFile(LAYOUT, Object.assign({}, data, { body }), {
|
|
cache: CACHE,
|
|
filename: LAYOUT
|
|
});
|
|
|
|
res.set('Content-Type', 'text/html; charset=utf-8');
|
|
res.send(html);
|
|
return html;
|
|
}
|
|
|
|
function esc(s) {
|
|
return String(s).replace(/&/g, '&').replace(/</g, '<')
|
|
.replace(/>/g, '>').replace(/"/g, '"');
|
|
}
|
|
|
|
// Small self-contained themed page for 401/403/404/500.
|
|
function renderError(req, res, status, title, message) {
|
|
const html = `<!DOCTYPE html>
|
|
<html lang="en" data-theme="dark">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="robots" content="noindex, nofollow">
|
|
<title>${esc(status)} | ${esc(APP_NAME)}</title>
|
|
<link rel="stylesheet" href="/web_template/base.css?v=${esc(assetVersion)}">
|
|
</head>
|
|
<body>
|
|
<main class="lt-main lt-container">
|
|
<div class="lt-frame">
|
|
<div class="lt-alert lt-alert--error">
|
|
<strong>${esc(status)}: ${esc(title)}</strong>
|
|
<p>${esc(message)}</p>
|
|
</div>
|
|
<p><a class="lt-btn lt-btn-secondary lt-btn-sm" href="/">Return to dashboard</a></p>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
`;
|
|
res.status(status).set('Content-Type', 'text/html; charset=utf-8').send(html);
|
|
}
|
|
|
|
module.exports = { renderPage, renderError, assetVersion };
|