UNPKG

hono-sess

Version:

A Simple Session Middleware for Hono

53 lines 1.96 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.warning = exports.deprecate = exports.debug = void 0; exports.hash = hash; exports.issecure = issecure; exports.expressCookieOptionsToHonoCookieOptions = expressCookieOptionsToHonoCookieOptions; const crypto_1 = require("crypto"); const debug_1 = require("debug"); const depd_1 = require("depd"); exports.debug = (0, debug_1.default)('hono-sess'); exports.deprecate = (0, depd_1.default)('hono-sess'); exports.warning = 'Warning: connect.session() MemoryStore is not\n' + 'designed for a production environment, as it will leak\n' + 'memory, and will not scale past a single process.'; function hash(session) { var str = JSON.stringify(session, function (key, val) { if (this === session && key === 'cookie') { return; } return val; }); return crypto_1.default.createHash('sha1').update(str, 'utf8').digest('hex'); } function issecure(req, trustProxy) { if (req.url.startsWith('https://') || req.url.startsWith('wss://')) { return true; } if (trustProxy === false) { return false; } var header = req.header('x-forwarded-proto') || ''; var index = header.indexOf(','); var proto = index !== -1 ? header.substring(0, index).toLowerCase().trim() : header.toLowerCase().trim(); return proto === 'https'; } function expressCookieOptionsToHonoCookieOptions(options, req, proxy) { const { priority, ...rest } = options; return { ...rest, sameSite: options.sameSite === true ? 'strict' : options.sameSite === false ? 'lax' : options.sameSite === 'none' ? 'none' : undefined, expires: options.expires || undefined, secure: options.secure === 'auto' ? issecure(req, proxy) : options.secure, }; } //# sourceMappingURL=utils.js.map