Comments (6)
@bovino I guess that's a generic question on how to reuse code in javascript. Is there a specific use case you looking for?
from kong-js-pdk.
i would like to see plugin samples available showing how to perform code reuse beetweb two custom JS plugins... or better yet, samples showing a similar capability we have in Lua where one plugin can directly extend another (not sure if this can be done with JS plugins)
if this helps, i can describe some "specific" scenario as follows:
JS plugin 1 - a basic validation plugin (supports validation only on header field and path variables)
JS plugin 2 - the "advanced" or "extended" version of the basic validation plugin, that extends the parent plugin and add a few more validation capabilities (allows you to apply validation on query params and body content)
i can think of some better scenarios if this is not good enough as a starting point :-)
thanks for your work
from kong-js-pdk.
this is pretty easy to do if following the plugin conventions in the examples. The only thing to work around really is name collisions.
'use strict'
// Extending local a plugin
const {Plugin: LocalPlugin, Schema: LocalSchema} = require('./local-plugin')
const {version: Version} = require('./package.json')
class Plugin extends LocalPlugin {
constructor(config) {
super(config)
// other setup code
}
async access(kong) {
// logic
// logic
return super.access(kong)
}
}
module.exports = {
Plugin
, Version
, Priority: 0
, Schema: [
...LocalSchema
, {foo: {type: 'string'}}
]
}
'use strict'
// Extending a plugin from npm package
const {Plugin: KongPlugin, Schema: KongSchema} = require('@myorg/kong-plugin')
const {version: Version} = require('./package.json')
class Plugin extends KongPlugin {
constructor(config) {
super(config)
// other setup code
}
async access(kong) {
// logic
// logic
return super.access(kong)
}
}
module.exports = {
Plugin
, Version
, Priority: 0
, Schema: [
...KongSchema
, {foo: {type: 'string'}}
]
}
from kong-js-pdk.
We don't currently have plans to add these types of examples to our documentation, but feel free to open a PR if you have specific suggestions.
from kong-js-pdk.
Is this project being abandoned?
from kong-js-pdk.
Is this project being abandoned?
We don't currently have plans to add these specific documentation enhancements, but we also don't plan to abandon this project. As per my review of yesterday, it seems that there are a couple of outstanding documentation items as well as enhancements that could be made. At this point, though, we don't have customers asking for these enhancements. We would certainly be interested in contributions in that regard.
from kong-js-pdk.
Related Issues (20)
- Issues running tests HOT 4
- Critical severity alert on msgpack dependency HOT 2
- How to add X-Kong-Upstream-Status header to response HOT 4
- Share Data between Plugins in Kong JS PDK HOT 2
- How to set no_consumer flag with kong-js-pdk Schema HOT 4
- Reference to a incorrect module functions HOT 3
- Kong unable to load js plugin HOT 10
- Simplify Module Loading HOT 7
- Plugin Test Case - Cannot use import statement outside a module error HOT 2
- How to convert the response obtained from getRawBody() to a readable format ? HOT 2
- package.json no longer includes files for plugin_test.js HOT 1
- Incorrect assignment of mocked log functions in plugin_test.js
- Server tries to load all files in the folder as a plugin and fails to start HOT 3
- Problem reading gzipped kong.service.response.get_raw_body() HOT 11
- Modifying response body (no body_filter phase?) HOT 3
- Question: How to wrote Unit tests using plugin_test.js HOT 1
- Question: How to see plugin error inside docker container logs HOT 2
- Missing plugin socket HOT 2
- Accessing Binary Files in plugin HOT 3
- cannot serialize object to string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kong-js-pdk.