Giter Site home page Giter Site logo

configurableserverfactory's Introduction

Project Goal

this is a demo project for backend architecture of config base http server this project aim to make server route config more clear,

Usage

you can pass the config object into ConfigurableServerFactory or use standard express function to add route, like router.get()

config object schema:

  1. Config Object Schema:
    1. isYaml - boolean(optional): request and response format, which are default to json
  2. rules - array of object:
    1. method - string: http method name in [all, use, get, post, put, delete]
    2. url - string(optional): route path
    3. callBack - function(optional): callBack for this rule
    4. validateHeader - object(optional): properties are
      1. name: header name
      2. regex: regex to valid header
      3. error: throw the error if the validation is failed
    5. validateCookies - object(optional): the usage is as same as validateHeader
    6. removeQueryString - boolean(optional): remove the url query string it's true

for example, in config.rules

{
  method: 'get',
  url: `${BASE_PATH}/resource`,
  callBack: (req, res, next) => {
    req.url = req.url.replace(`${BASE_PATH}/resource`, `${BASE_PATH}/static/assets`)
    next()
  }
}

is equal to

app.get(`${BASE_PATH}/resource`, (req, res) => {
  (req, res, next) => {
    req.url = req.url.replace(`${BASE_PATH}/resource`, `${BASE_PATH}/static/assets`)
    next()
  }
})

Available script

yarn start

to start the express server

configurableserverfactory's People

Contributors

jadson666 avatar

Watchers

James Cloos avatar  avatar

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.