koa-xframe
Version:
X-Frame-Options HTTP response header utility for Koa
44 lines (33 loc) • 1.14 kB
JavaScript
;
var _regeneratorRuntime = require('babel-runtime/regenerator')['default'];
exports.__esModule = true;
var _this = this;
var canBe = ['DENY', 'SAMEORIGIN'];
var xFrame = function xFrame() {
var value = arguments.length <= 0 || arguments[0] === undefined ? 'DENY' : arguments[0];
if (! ~canBe.indexOf(value)) {
throw new Error('X-Frame-Options value \'' + value + '\' is not allowed. Expected \'DENY\' or \'SAMEORIGIN\'');
}
return function callee$1$0(ctx, next) {
var
// headers only necessary for HTML pages
type;
return _regeneratorRuntime.async(function callee$1$0$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
context$2$0.next = 2;
return _regeneratorRuntime.awrap(next());
case 2:
type = ctx.type;
if (type && ~type.indexOf('text/html')) {
ctx.response.set('X-Frame-Options', value);
}
case 4:
case 'end':
return context$2$0.stop();
}
}, null, _this);
};
};
exports['default'] = xFrame;
module.exports = exports['default'];