A mock server of Ctrip's apollo configuration service.
This is a mock server only for testing, so it barely has any argument type checking and fault tolerance.
$ npm i apollo-mock-server
const {ConfigService} = require('apollo-mock-server')
require('http').createServer(
new ConfigService({
pollingTimeout: 3000
}).callback()
)
.listen(8888)
- options
Object
- pollingTimeout
number=60000
If there is no update notifications inoptions.pollingTimeout
milliseconds, then config service will tell the client with status304
- configDelay
number=0
The APIs to get the configuration will be delayed inconfigDelay
. This option is to mimic the timeout scenarios.
- pollingTimeout
Return a callback function suitable for the http.createServer() method to handle a request.
- port?
number
port to listen
Listen to a port. If port
is not specified, it will get an available port by using get-port
Returns a promise of the port
used
config.listen()
.then(port => {
console.log(`server started at http://127.0.0.1:${port}`)
})
Enable or disable the API of get configurations, including both:
/configs
/configfiles
If disabled, the two APIs will both response with status 404
If enabled, the two APIs above will response a bad JSON string
If disabled, the API /notifications/v2
will response with status 404
The admin client for super user
const {superAdmin} = require('apollo-mock-server')
superAdmin
.app('my-application')
.cluster('default')
.namespace('application')
// Changes the config value
.set('portal.elastic.cluster.name', 'hermes-es-jp')
// Emit update notifications
.publish()