UNPKG

@appsemble/node-utils

Version:

NodeJS utilities used by Appsemble internally.

20 lines 960 B
import { addDays } from 'date-fns'; import { assertKoaCondition } from '../../../index.js'; export function createSecurityHandler({ getApp, getSecurityEmail }) { return async (ctx) => { const app = await getApp({ context: ctx, query: { attributes: ['id', 'updated'] } }); assertKoaCondition(app != null, ctx, 404, 'App not found'); const expires = addDays(new Date(app.$updated ?? app.$created), 180); const securityEmail = getSecurityEmail(); ctx.type = 'text/plain; charset=utf-8'; ctx.body = [ `Contact: mailto:${securityEmail}`, `Expires: ${expires.toISOString().replace(/\.\d{3}Z$/, 'Z')}`, `Canonical: ${ctx.URL.origin}/.well-known/security.txt`, 'Policy: https://gitlab.com/appsemble/appsemble/-/blob/main/SECURITY.md', 'Preferred-Languages: en, nl', '', ].join('\n'); }; } //# sourceMappingURL=securityHandler.js.map