restify-loader

2.1.6 • Public • Published

Build Status

RESTify Loader

Load in Restify and Setup basic functionality ( Remove the restify Boilerplate ).

Installation

npm install restify-loader

Usage

 
// REST API Server:
let server = require('restify-loader')({
    dir: __dirname,
    name: 'fresca',
    version: '1.0.0',
    dirs: {
        libs: 'libraries',
        middleware: 'middleware',
        schemas: 'schemas'
    }
}, {
    someData: 'foo'
})
 
// Add custom stuff to root Server object
// server.use( passport )
 
// Listen for connections:
server.listen( process.env.PORT || 8080, () => {
    console.log( `Listening to port: ${PORT}` )
})
 

Parameters

restifyLoader( options, routeParams ) returns server instance.

Note that it will always recursively load in all files in the routes directory. Do not put routes in the 'dirs' object.

  • options ( Object ) [ required ]

    • dir ( String ) [ required ] - Directory from which we execute from. Almost always pass in __dirname in your main application.
    • name ( String ) [ required ] - Default: 'rest-api' - This will be in your HTTP responses. Also this is what all debug messages will be logged under.Eg: If your app name is fresca you will enable debugging via: DEBUG=fresca* npm start.
    • version ( String ) [ required ] - Default: '1.0.0' - This will be returned in your HTTP responses. This is useful for versioning APIs.
    • dirs ( Object ) [ optional ] - This is a key value set of directories we should recursively require in and attach to every Route instance. In the above example libraries, middleware, and schemas are all directories with multiple js files. Every js file will be required in and stored as the filename. If in libraries directory you had a file named helpers.js it would be accessible in all Routes as this.libs.helpers.
    • raven ( Object ) [ optional ]
      • DSN ( String ) [ required ] - DSN string used to report back to Sentry.
      • context ( Object ) [ optional ] - Additional context to add to Sentry messages.
  • routeParams ( Object ) [ optional ] - This is arbitrary data you want passed to each route instance. Useful for passing DB connections, etc. to routes.

  • Returns :: Server ( Object ) - Instance of Restify libraries server object. Very similar to Express' server / app instance. You can attach additional things to the server object before listening. Passport or other Auth for instance.

License

MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i restify-loader

Weekly Downloads

2

Version

2.1.6

License

MIT

Unpacked Size

32.8 kB

Total Files

6

Last publish

Collaborators

  • stackdot