Permalink
Browse files

Step 1.11: Add permitter helper

  • Loading branch information...
DAB0mB committed Dec 12, 2016
1 parent 1509c1e commit 013be1a6705fb0be864c6680a723d43f47f93eef
Showing with 29 additions and 0 deletions.
  1. +29 −0 helpers/permitter.js
@@ -0,0 +1,29 @@
const Boom = require("boom");
const Hapi = require("hapi");
const IpGrabber = require("./ip_grabber");

// These addresses will be permitted by default
const defaultPermissions = [
IpGrabber.local(), "127.0.0.1", "localhost"
];

// Manage file permissions
function file(path, permissions, req, rep) {
// Apply default permissions
permissions = permissions.concat(defaultPermissions);
// Request address
let remoteAddress = req.info.remoteAddress;

// If not permitted, reply error
if (permissions.indexOf(remoteAddress) == -1) {
let err = new Boom.forbidden("Missing permissions");
return rep(err);
}

// If permitted, reply file
rep.file(path);
}

module.exports = {
file
};

0 comments on commit 013be1a

Please sign in to comment.