gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

make config file support javascript #74

Closed jf3096 closed 5 years ago

jf3096 commented 7 years ago

Changes:

  1. make config file support javascript (main changes)
  2. introduce chalk to highligh route in console or shell. (minor)

description: In my team, more than 1 ppl work together so we might need dynamic settings base on our needs such as port, latency etc. Also, we might need to integrate most config as well. In order to overcome my needs, make the config file support javascript is much more better than a static JSON file. This is because we can do whatever we want like split file, create class, declare our mock file pattern etc.

Here is how I use:

const {createWebService, mergeConfig} = require('./utils');
const baseConfig = require('./baseConfig');

module.exports = () => {
    return mergeConfig(
        baseConfig,
        [
            /**
             * created a rule. my rule is to create the mock url exactly same as my json directory as url is unique.
             */
            createWebService(`core/cpanel/promotion/manager/init`),
            /**
             * create mock here...
             */
        ]
    )
};
gstroup commented 7 years ago

Thanks for the contribution. I've considered making the config file support Javascript. Seems like a good idea. Can't remember, but there was a reason I didn't do it before. I hope to dig in to your code soon, and hopefully merge it in. Thank you.

gstroup commented 5 years ago

Javascript config files are now supported! See PR #100