0.0.6 • Published 6 years ago

restify-magic v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Restify Magic

Magic resources for restify

Installation

npm install restify-magic

Usage Example

The first example illustrates the basic usage of restify-magic. It initializes a restify server that maps arbitrary REST resources to /:resource with the resources stored in a local NeDB database:

require("restify-magic")
  .createServer()
  .listen(3000);

The second example represents a good starting point for a more complex application. It initializes a restify server that maps arbitrary REST resources to /r/:resource and shares the contents of the public/ directory under /:

var restify = require("restify"),
  magic = require("restify-magic"),
  server;

// create the rest server
server = magic.createServer({ prefix: "r", debug: process.env.DEBUG });

// static server
server.get("/.*", restify.serveStatic({
  directory: "./" + (process.env.PUBLIC || "public"),
  default: "index.html"
}));

// start listening
server.listen(process.env.PORT || 3000, function () {
  console.log("Server listening at %s", server.url);
});

Note that above example allows you to toggle detailed logging via the environment variable DEBUG, as well as specifying a custom public directory or listen port via the PUBLIC and PORT variables.

Configuration Options

createServer accepts the following configuration options:

  • store: [restify.Store]: A custom data store to be used
  • prefix: [string]: URL prefix to be prepended before all resource URLs
  • server: [restify.Server]: Custom restify server to use
  • debug: [bool]: Enable debug logging (all requests are logged to the console)
  • middleware: [Array]: An array of custom middleware to be added to the restify server

Authentication

If the body of a post or put request contains a key called password, a salt sha-1 hash is generated and used to store the given password in encrypted form. Likewise, if a get request contains the key password in its parameters, it the password is matched with the stored encrypted password.

Custom Data Stores

NeDB

Usage example:

var restify = require("restify"),
  magic = require("restify-magic"),
  store = magic.nedbStore({ path: "path/to/your/db" }),
  server = magic.createServer({ store: store });

By providing a path option, a separate nedb datafile is created in the path directory for each resource.

Authors

License

MIT

0.0.6

6 years ago

0.0.5

9 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago