Giter Club home page Giter Club logo

well-known-json-js's Introduction

Build Status Coverage Status Dependency Status License

well-known-json

Illustrative usage example

import express from 'express';
import wkj from 'well-known-json';

const app = express();

// Each resource will be a separate JSON resource under the well-known endpoint
const 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 that 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)
const 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
const wkjMiddleware = wkj(resources, options);

// 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)

well-known-json-js's People

Contributors

abalmos avatar aultac avatar awlayton avatar cyrusbowman avatar dependabot[bot] avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.