restify-loader v2.1.6
RESTify Loader
Load in Restify and Setup basic functionality ( Remove the restify Boilerplate ).
Installation
npm install restify-loaderUsage
// 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
routesdirectory. Do not putroutesin the 'dirs' object.
options ( Object ) required
- dir ( String ) required - Directory from which we execute from. Almost always pass in
__dirnamein 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
frescayou 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
Routeinstance. In the above examplelibraries,middleware, andschemasare all directories with multiple js files. Every js file will be required in and stored as the filename. If inlibrariesdirectory you had a file named helpers.js it would be accessible in allRoutes asthis.libs.helpers. - raven ( Object ) optional
- dir ( String ) required - Directory from which we execute from. Almost always pass in
routeParams ( Object ) optional - This is arbitrary data you want passed to each
routeinstance. 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
6 years ago
6 years ago
6 years ago
7 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago