Coder Social home page Coder Social logo

copperfield's Introduction

copperfield

Server-level houdin validation for hapi.

NPM Version Build Status Coverage Status Dependencies Dev Dependencies

Table of Contents

Installation

Install via NPM.

$ npm install copperfield

Usage

Register the package as a server plugin to enable validation for each route that parses — parse: true — and reads the request payload into memory — output: 'data'. For every other route with a different configuration, the validation is skipped.

If the validation fails, a joi-like 400 Bad Request error is returned alongside an additional content-validation: failure response header. If everything is ok, the response will ultimately contain a content-validation: success header.

Example

const Hapi = require('hapi');
const Copperfield = require('copperfield');

try {
    const server = new Hapi.Server();

    await server.register({
        plugin: Copperfield,
        options: {
            // Allow png files only
            whitelist: ['image/png']
        }
    });

    server.route({
        options: {
            payload: {
                output: 'data',
                parse: true
            }
            // go nuts
        }
    });

    await server.start();
}
catch (err) {
    throw err;
}

Supported File Types

The same as file-type.

copperfield's People

Contributors

greenkeeperio-bot avatar ruiquelhas avatar

Watchers

 avatar  avatar

copperfield's Issues

Update package keywords

Update the keywords array in the package.json file to ensure they better match the intent of the package itself and to aim for better discoverability.

houdin breaking changes

A non-major update of houdin introduced a change in behavior handling different invalid file types. This seems to be a breaking change in the way the errors are bubbled into hapi using supervizor, because there are now multiple reply() calls happening.

Debug: internal, implementation, error 
    Error: reply interface called twice
    at Object.exports.unique.exports.contain.exports.reachTemplate.exports.assert.condition [as assert] (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/hoek/lib/index.js:736:11)
    at Function.internals.Reply.interface.internals.continue.internals.response (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/reply.js:164:10)
    at bound (domain.js:287:14)
    at Function.runBound (domain.js:300:12)
    at reply (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/reply.js:72:22)
    at bound (domain.js:287:14)
    at runBound (domain.js:300:12)
    at /home/rui-quelhas/Developer/other/personal/copperfield/node_modules/supervizor/lib/index.js:28:24
    at /home/rui-quelhas/Developer/other/personal/copperfield/node_modules/houdin/lib/index.js:51:20
    at /home/rui-quelhas/Developer/other/personal/copperfield/node_modules/houdin/lib/index.js:22:20
    at Array.forEach (native)
    at Object.internals.validate.next [as validate] (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/houdin/lib/index.js:10:45)
    at Object.internals.validate.exports.validate.next [as validator] (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/houdin/lib/index.js:37:15)
    at /home/rui-quelhas/Developer/other/personal/copperfield/node_modules/supervizor/lib/index.js:18:17
    at finalize (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/request.js:453:22)
    at iterate (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/items/lib/index.js:36:13)
    at Object.exports.serial (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/items/lib/index.js:39:9)
    at /home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/request.js:456:15
    at internals.Protect.run.finish [as run] (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/protect.js:60:12)
    at internals.Request._listenRequest.internals.Request._execute.internals.Request._lifecycle.internals.Request._invoke.callback._protect.run [as _invoke] (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/request.js:436:19)
    at each (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/request.js:398:25)
    at iterate (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/items/lib/index.js:36:13)
    at done (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/items/lib/index.js:28:25)
    at internals.Auth.test.internals.Auth.payload.finalize (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/auth.js:235:16)
    at each (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/request.js:401:16)
    at iterate (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/items/lib/index.js:36:13)
    at done (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/items/lib/index.js:28:25)
    at request._protect.run (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/route.js:341:20)
    at /home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/lib/route.js:380:20
    at next (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/subtext/lib/index.js:45:26)
    at wrapped (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/hoek/lib/index.js:875:20)
    at finalize (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/subtext/lib/index.js:327:16)
    at onPart.writeFile.Wreck.read.onClose (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/subtext/lib/index.js:433:16)
    at g (events.js:260:16)
    at emitNone (events.js:72:20)
    at emit (events.js:166:7)
    at exports.Dispenser.internals.Dispenser.options._parts.on._lines.on.internals.Dispenser._emit (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/subtext/node_modules/pez/lib/index.js:196:15)
    at _parts.on._lines.on.finish (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/subtext/node_modules/pez/lib/index.js:125:14)
    at Immediate.wrapped [as _onImmediate] (/home/rui-quelhas/Developer/other/personal/copperfield/node_modules/hapi/node_modules/hoek/lib/index.js:875:20)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.