mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-25 14:02:03 +02:00
Initial commit
This commit is contained in:
8
node_modules/frameguard/dist/index.d.ts
generated
vendored
Normal file
8
node_modules/frameguard/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="node" />
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
interface FrameguardOptions {
|
||||
action?: string;
|
||||
domain?: string;
|
||||
}
|
||||
declare const _default: (options?: FrameguardOptions | undefined) => (_req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
||||
export = _default;
|
57
node_modules/frameguard/dist/index.js
generated
vendored
Normal file
57
node_modules/frameguard/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
function parseActionOption(actionOption) {
|
||||
var invalidActionErr = new Error('action must be undefined, "DENY", "ALLOW-FROM", or "SAMEORIGIN".');
|
||||
if (actionOption === undefined) {
|
||||
actionOption = 'SAMEORIGIN';
|
||||
}
|
||||
else if (actionOption instanceof String) {
|
||||
actionOption = actionOption.valueOf();
|
||||
}
|
||||
var result;
|
||||
if (typeof actionOption === 'string') {
|
||||
result = actionOption.toUpperCase();
|
||||
}
|
||||
else {
|
||||
throw invalidActionErr;
|
||||
}
|
||||
if (result === 'ALLOWFROM') {
|
||||
result = 'ALLOW-FROM';
|
||||
}
|
||||
else if (result === 'SAME-ORIGIN') {
|
||||
result = 'SAMEORIGIN';
|
||||
}
|
||||
if (['DENY', 'ALLOW-FROM', 'SAMEORIGIN'].indexOf(result) === -1) {
|
||||
throw invalidActionErr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function parseDomainOption(domainOption) {
|
||||
if (domainOption instanceof String) {
|
||||
domainOption = domainOption.valueOf();
|
||||
}
|
||||
if (typeof domainOption !== 'string') {
|
||||
throw new Error('ALLOW-FROM action requires a string domain parameter.');
|
||||
}
|
||||
else if (!domainOption.length) {
|
||||
throw new Error('domain parameter must not be empty.');
|
||||
}
|
||||
return domainOption;
|
||||
}
|
||||
function getHeaderValueFromOptions(options) {
|
||||
options = options || {};
|
||||
var action = parseActionOption(options.action);
|
||||
if (action === 'ALLOW-FROM') {
|
||||
var domain = parseDomainOption(options.domain);
|
||||
return action + " " + domain;
|
||||
}
|
||||
else {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
module.exports = function frameguard(options) {
|
||||
var headerValue = getHeaderValueFromOptions(options);
|
||||
return function frameguard(_req, res, next) {
|
||||
res.setHeader('X-Frame-Options', headerValue);
|
||||
next();
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user