javascript - Preventing relative require calls from modules in a specific folder -
this sound odd, i'd modules in specific directory able require resources out of node_modules , not other part of application.
in specific directory:
require('fs')
-- should workrequire('../../something')
-- deniedrequire('./another')
-- denied
is remotely possible in node?
you make module that'll act require-proxy:
module.exports.require2 = function() { if (arguments[0][0] !== '.') { return require.apply(this, arguments); } else { throw new error('can\'t require relative modules'); } }
of course, opt-in developers:
var require2 = require('require2'); var fs = require2('fs'); //everything's var fss = require2('./fss'); //throws error
kind of similar idea thlorenz's proxyquire.
Comments
Post a Comment