Giter VIP home page Giter VIP logo

oia's People

Contributors

dependabot[bot] avatar pauldcomanici avatar

Stargazers

 avatar  avatar

oia's Issues

[amiddy] Ability to use a base configuration for defaults and placeholders and a specific config where you can define placeholder values.

Short description

Ability to use a base configuration for defaults and placeholders and a specific config where you can define placeholder values.

The problem

For amiddy, there is the ability to use a config file to define how the middleware will work.

There is the use-case where you have multiple environments for your application, and your configurations are just a copy/paste with minor changes.

Let's take an example. You are working for an Application that has 3 environments: acceptance, staging & production.
There should be 3 amiddy configs:
amiddy.acceptance.json:

{
  "source": {
    "ip": "127.0.0.1",
    "https": true,
    "port": 443
  },
  "deps": [
    {
      "name": "acceptance.gateway.example.com",
      "https": true,
      "port": 443,
      "patterns": [
        "/login",
        "/logout",
        "/api/**"
      ],
      "mocks": [
        {
          "patterns": ["info**"],
          "response": "",
          "status": 200,
          "fixture": "__local__/info.txt"
        }
      ]
    }
  ],
  "proxy": {
    "response": {
      "headers": {
        "X-Special-Proxy-Header": "on-response"
      }
    }
  },
  "vhost": {
    "name": "acceptance.example.com",
    "https": true,
    "port": 443
  }
}

amiddy.staging.json:

{
  "source": {
    "ip": "127.0.0.1",
    "https": true,
    "port": 443
  },
  "deps": [
    {
      "name": "staging.gateway.example.com",
      "https": true,
      "port": 443,
      "patterns": [
        "/login",
        "/logout",
        "/api/**"
      ],
      "mocks": [
        {
          "patterns": ["info**"],
          "response": "",
          "status": 200,
          "fixture": "__local__/info.txt"
        }
      ]
    }
  ],
  "proxy": {
    "response": {
      "headers": {
        "X-Special-Proxy-Header": "on-response"
      }
    }
  },
  "vhost": {
    "name": "staging.example.com",
    "https": true,
    "port": 443
  }
}

amiddy.production.json:

{
  "source": {
    "ip": "127.0.0.1",
    "https": true,
    "port": 443
  },
  "deps": [
    {
      "name": "production.gateway.example.com",
      "https": true,
      "port": 443,
      "patterns": [
        "/login",
        "/logout",
        "/api/**"
      ],
      "mocks": [
        {
          "patterns": ["info**"],
          "response": "",
          "status": 200,
          "fixture": "__local__/info.txt"
        }
      ]
    }
  ],
  "proxy": {
    "response": {
      "headers": {
        "X-Special-Proxy-Header": "on-response"
      }
    }
  },
  "vhost": {
    "name": "production.example.com",
    "https": true,
    "port": 443
  }
}

Now, what if I need to:

  • add a new mock?
  • add a new pattern for the dependency?
  • add a new dependency?
  • remove an existing pattern for the dependency?
  • ...

I would need to change all 3 files every time and to add/remove the same stuff.

Solution

  • have a base config that contains placeholders
  • have a specific config that defined the placeholder and the value

Example, based on the above data:
base.amiddy.json

{
  "source": {
    "ip": "127.0.0.1",
    "https": true,
    "port": 443
  },
  "deps": [
    {
      "name": "__DEP_NAME__",
      "https": true,
      "port": 443,
      "patterns": [
        "/login",
        "/logout",
        "/api/**"
      ],
      "mocks": [
        {
          "patterns": ["info**"],
          "response": "",
          "status": 200,
          "fixture": "__local__/info.txt"
        }
      ]
    }
  ],
  "proxy": {
    "response": {
      "headers": {
        "X-Special-Proxy-Header": "on-response"
      }
    }
  },
  "vhost": {
    "name": "__VHOST_NAME__",
    "https": true,
    "port": 443
  }
}

amiddy.acceptance.json:

{
  "__DEP_NAME__": "acceptance.gateway.example.com",
  "__VHOST_NAME__": "acceptance.example.com"
}

staging.production.json:

{
  "__DEP_NAME__": "staging.gateway.example.com",
  "__VHOST_NAME__": "staging.example.com"
}

amiddy.production.json:

{
  "__DEP_NAME__": "production.gateway.example.com",
  "__VHOST_NAME__": "production.example.com"
}

If we are to answer the same questions are presented initially we need to change only the base config.

Notes

This implementation should not affect in any way existing behavior

all args, not just in catch?

I'm loving the babel auto logger. It's super helpful. I'm not seeing how to log the arguments for non-catch block calls. Is that possible? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.