@oada/well-known-json
Middleware for JSON Well-Known resources
Last updated 4 months ago by aultac .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @oada/well-known-json 
SYNC missed versions from official npm registry.

BuildStatus CoverageStatus DependencyStatus License

well-known-json

Illustraive usage example

var app = require('express')()
var wkj = require('well-known-json')

// Each resource will be a separate JSON resource under the well-known enpoint
var resources = {
  'foo/bar': {
    // Will be at .well-known/foo/bar
    a: 1,
    b: 2
  },
  baz: {
    // Will be at .well-known/baz
    obj: {
      // Function properties are evaluated for each response generated
      now: function () {
        return Date.now()
      },
      // String properties which look like relative URIs are converted to absolute URIs
      uri: './relative/path'
    },
    // Other things become JSON normally
    str: 'words here'
  }
}

// Options for well-known-json middleware (and middlewares it uses)
var options = {
  // Passed directly to cors middleware
  cors: {
    /* whatever you can give the cors middleware */
  },
  // Optional base for resolving relative URIs
  // If omitted, wkj will use the protocol and host to which the request was sent
  baseUri: 'http://example.org/foo'
}

// Create a middleware instance
var wkjMiddleware = wkj(options, resources)

// Mount the middleware with express
app.use(wkjMiddleware)

// Add additional resources after creation
// They will be merged with a prexisting resource with the same name
wkjMiddleware.addResource('baz', {
  more: 'stuff', // Add key more to baz
  str: 'different words here' // Overwrite key str in baz from before
})

Features

  • Enables CORS (including pre-flight) for its corresponding JSON documents
  • Converts relative URIs to absolute
  • Can have functions "in the documents" which get evaluated for each request
  • Supports de-facto standard for reverse proxies (i.e. X-Forwarded-* headers)

Current Tags

  • 1.0.1                                ...           latest (4 months ago)

2 Versions

  • 1.0.1                                ...           4 months ago
  • 1.0.0                                ...           6 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |