npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

feathers-kong

v1.0.5

Published

A Feathers service for Kong API Gateway admin API

Downloads

45

Readme

feathers-kong

Build Status Coverage Status JavaScript Style Guide Dependency Status npm

A Feathers service for Kong API Gateway admin API

Installation

npm install feathers-kong --save

Documentation

Please refer to the Kong admin API docs for options that can be passed. Feathers service methods map to the following Kong methods:

  • Feathers find -> Kong list all or when not using Consumer service, list resources of consumer by setting params.query.consumer with Kong consumer ID
  • Feathers get -> Kong get resource by id by setting id with resource ID & when not using Consumer service, set params.query.consumer with Kong consumer ID. otherwise it will return consumer by resource ID when supported
  • Feathers create -> Kong create resource. set params.query.consumer to create resource on consumer
  • Feathers patch -> Kong update resource by id
  • Feathers update -> Kong update resource by id
  • Feathers remove -> Kong delete resource by id

If a method is not supported by Kong for a given resource it is not support here as well.

Available Services

The following services are supported and map to the appropriate Kong resource:

  • Consumer
  • Acl
  • Jwt
  • KeyAuth

This is pretty important! Since this connects to your Kong admin API, you want to make sure that you don't expose these endpoints via your app unless the user has the appropriate permissions. You can prevent any external access by doing this:

const { Forbidden } = require('@feathersjs/errors');

app.service('/kong/consumers').before({
  all: [
    context => {
      if (context.params.provider) {
        throw new Forbidden('You are not allowed to access this');
      }
    }
  ]
});

Complete Example

Here's an example of a Feathers server that uses feathers-authentication for local auth. It includes a users service that uses feathers-mongoose. Note that it does NOT implement any authorization.

const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const { Consumer } = require('feather-kong');

// Initialize the application
const app = feathers()
  .configure(express.rest())
  .configure(socketio())
  // Needed for parsing bodies (login)
  .use(express.json())
  .use(express.urlencoded({ extended: true }))
  // A simple Message service that we can used for testing
  .use('/kong/consumers', new Consumer({ url: 'http://localhost:8001' }))
  .use('/', feathers.static(__dirname + '/public'))
  .use(express.errorHandler({ html: false }));


function validateConsumer() {
  return function(hook) {
    console.log('Validating consumer code goes here');
  };
}


const consumerService = app.service('kong/consumers');

consumerService.before({
  create: [validateConsumer()]
});

const consumer = {
  username: 'john',
  custom_id: 'u1'
};

consumerService.create(consumer).then(result => {
  console.log('Consumer created', result);
}).catch(error => {
  console.log('Error creating consumer', error);
});

app.listen(3030);

console.log('Feathers authentication app started on 127.0.0.1:3030');

License

Copyright (c) 2019

Licensed under the MIT license.