Skip to content

Instantly share code, notes, and snippets.

@hisco
Last active July 23, 2019 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisco/6046a9b907d4f17a26782ab7932449c2 to your computer and use it in GitHub Desktop.
Save hisco/6046a9b907d4f17a26782ab7932449c2 to your computer and use it in GitHub Desktop.
Stubz express example - WIP
{
"name": "hello-stubz",
"version": "0.0.1",
"description": "A simple example of subz server.",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"@stubz/core":"0.0.14",
"stubz":"0.0.7"
},
"engines": {
"node": "8.x"
},
"repository": {
},
"license": "MIT"
}
const {
StubzExpress,
StubzExpressRouter
} = require('stubz');
const {
StubzRouteStaticResponse
} = require('@stubz/core');
const stubzServer = new StubzExpress({
ports : [process.env.PORT || 3001],
//adminPort: 3002 //If you want control api
fsControl:{} // This setups fs control with default configurations
});
const dogNamesRouter = new StubzExpressRouter({name:'dogs',route:'/names'});
dogNamesRouter.get('/' ,{
statusCode : 200,
json : ['Charlie' , 'Max']
})
.setOption('twoDogs')
.defaultOn();
dogNamesRouter.get('/' , new StubzRouteStaticResponse({
json: []
}))
.setOption('noDogs')
.defaultOff();
const otherRouter = new StubzExpressRouter({name:'tasks',route:'/tasks'});
otherRouter.get('/' , new StubzRouteStaticResponse({
json:[]
}))
.setOption('noTasks')
.defaultOn();
stubzServer.addPlugins([
dogNamesRouter,
otherRouter
])
stubzServer.start();
// dogNamesRouter.setVariationsByName({ //You may programatically control the variations
// twoDogs: false,
// noDogs: true
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment