https://github.com/dekelev/feathers-kong
A Feathers service for Kong API Gateway admin API
https://github.com/dekelev/feathers-kong
api-gateway feathers feathersjs kong kong-admin
Last synced: 5 months ago
JSON representation
A Feathers service for Kong API Gateway admin API
- Host: GitHub
- URL: https://github.com/dekelev/feathers-kong
- Owner: dekelev
- License: mit
- Created: 2019-03-30T19:18:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-18T21:52:24.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T07:50:09.076Z (6 months ago)
- Topics: api-gateway, feathers, feathersjs, kong, kong-admin
- Language: JavaScript
- Size: 544 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-feathersjs - feathers-kong - A Feathers service for [Kong API Gateway](https://docs.konghq.com) admin API (Plugins / Utilities)
README
# feathers-kong
[](https://travis-ci.org/dekelev/feathers-kong)
[](https://coveralls.io/github/dekelev/feathers-kong?branch=master)
[](https://standardjs.com/)
[](https://david-dm.org/dekelev/feathers-kong)
[](https://www.npmjs.com/package/feathers-kong)> A Feathers service for [Kong API Gateway](https://docs.konghq.com) admin API
## Installation
```
npm install feathers-kong --save
```## Documentation
Please refer to the [Kong admin API docs](https://docs.konghq.com/1.0.x/admin-api/) 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 idIf 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:
```js
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.*
```js
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](LICENSE).