@trifrost/core
Version:
Blazingly fast, runtime-agnostic server framework for modern edge and node environments
23 lines (22 loc) • 600 B
JavaScript
import { getActiveCtx } from './use';
export const NONCEMARKER = 'tfnonce';
export function nonce() {
return getActiveCtx()?.nonce || null;
}
/**
* Nonce Window script setter for full-page ssr behavior
*
* @param {string} val - Nonce value
*/
export function NONCE_WIN_SCRIPT(val) {
if (typeof val !== 'string' || !val.length)
return '';
return [
'<script nonce="' + val + '">',
'Object.defineProperty(window,"$' + NONCEMARKER + '",{',
'value:"' + val + '",',
'configurable:!1,',
'writable:!1',
'})</script>',
].join('');
}