Giter VIP home page Giter VIP logo

kth-node-express-routing's Introduction

This is a wrapper for express route to allow generating named path files for app routes. It is used pƄ KTH node-web projects to pass urls to browser clients.

PageRouter

PageRouter allows us to register page style routes that are registered in the path definition files.

Usage:

const AppRouter = require('kth-node-express-routing').PageRouter
const getPaths = require('kth-node-express-routing').getPaths
const server = require('express')()

const systemRoute = AppRouter()
systemRoute.get('system.monitor', '/_monitor', function (req, res) { ... })
server.use('/', systemRoute.getRouter())

const appRoute = AppRouter()
appRoute.get('app.index', '/', function (req, res) { ... })
server.use('/', appRoute.getRouter())

const paths = getPaths()
/*
paths = {
  system: { 
    monitor: { 
      uri: '/_monitor',
      method: 'get
    }
  },
  app: { 
    index: { 
      uri: '/',
      method: 'get
    }
  }
}
*/

ApiRouter

ApiRouter allows us to register api endpoints by passing api endpoint definition objects from the paths file. It will set req.scope and add the authByApiKey middleware passed to ApiRouter IF the apiDefObj passed below evaluates apikey.scope_required == true

Usage in your node-api app:

// Middleware to protect enpoints with apiKey
const authByApiKey = passport.authenticate('apikey', { session: false })

const ApiRouter = require('kth-node-express-routing').ApiRouter
const apiRoute = ApiRouter(authByApiKey)

const apiDefObj = {
  uri: "/api/node/data/:id/api/node/v1",
  method: "GET",
  apikey: {
    scope_required: true,
    scopes: ["read"],
    type: "api_key"
  }
}

// A middleware adding the access scope requriements (req.scope) and the authByApiKey is automatically
// prepended to the middleware pipeline
apiRoute.register(apiDefObj, function (req, res) { ... })

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.