![Coverage](https://codecov.io/gh/kaelzhang/apollo-mock-server/branch/master/graph/badge.svg)
apollo-mock-server
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.
Install
$ npm i apollo-mock-server
Usage
const {ConfigService} = require('apollo-mock-server')
require('http').createServer(
new ConfigService({
pollingTimeout: 3000
}).callback()
)
.listen(8888)
new ConfigService(options)
- options
Object
- pollingTimeout
number=60000
If there is no update notifications in options.pollingTimeout
milliseconds, then config service will tell the client with status 304
config.callback(): Function
Return a callback function suitable for the http.createServer() method to handle a request.
config.listen(port?): Promise<port>
- 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}`)
})
config.enableFetch(enable)
Enable or disable the API of get configurations, including both:
If disabled, the two APIs will both response with status 404
config.enableFetchError(enable)
If enabled, the two APIs above will response a bad JSON string
config.enableUpdateNotification(enable)
If disabled, the API /notifications/v2
will response with status 404
superAdmin
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()
License
MIT