Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

falcor-hapi

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

falcor-hapi

A falcor server for hapi.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
3
Weekly downloads
 
Created
Source

falcor-hapi

Server middleware for falcor-hapi

Working usage example of the basic repro in falcor-hapi-demo/

Usage

Minimalistic example

var FalcorServer = require('falcor-hapi');
var Hapi = require('hapi');
var TestRouter = <your router here>;

var app = new Hapi.Server();
app.connection({
    host: "localhost",
    port: 9090
});

app.route({
    method: ['GET', 'POST'],
    path: '/model.json',
    handler: FalcorServer.dataSourceRoute(function(req, res) {
        return new TestRouter();
    })
});
app.start();

Hapi Plugin Usage

You can also register this module as an Hapi Plugin and use its provided Falcor handler.

Features
  • Provides restful router with cached routes out of the box.
  • Both the Hapi Request and Reply are available within your routes as this.req and this.reply.
  • Validates your routes with JOI.
  • You can provide your own initialize method to the router.
  • Alternately, you can provide your own Router class and the handler will mixin the logic to cache your routes and the base Falcor router class.
var Hapi = require('hapi');

var app = new Hapi.Server();
app.connection({
    host: "localhost",
    port: 9090
});

app.register(require('falcor-hapi'), function (err) {
   if (err) {
       console.error('Failed to load plugin:', err);
   }

   app.route({
     method: ['GET', 'POST'],
     path: '/model.json',
     handler: {
         falcor: {
             routes: routes,                                         // Your routes
             cacheRoutes: true,                                      // Whether to cache your routes, default to true
             options: {debug: true},                                 // Option to give to Falcor router
             initialize: function() {                                // Optional initialize method
                this.foo = this.req.payload.meaningoflife || 42;
             },
             routerClass: MyRouterClass                              // Optional routerClass to use
         }
     }
   });

   app.start();
});

Development

Please run linting before pushing on repo

npm run lint

Todo

  • Create mocha test for regression and development instead of using example

FAQs

Package last updated on 15 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc