Last active
July 23, 2019 04:35
-
-
Save hisco/6046a9b907d4f17a26782ab7932449c2 to your computer and use it in GitHub Desktop.
Stubz express example - WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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