this is a demo project for backend architecture of config base http server this project aim to make server route config more clear,
you can pass the config object into ConfigurableServerFactory
or use standard
express function to add route, like router.get()
- Config Object Schema:
isYaml
- boolean(optional): request and response format, which are default to json
- rules - array of object:
method
- string: http method name in [all, use, get, post, put, delete]url
- string(optional): route pathcallBack
- function(optional): callBack for this rulevalidateHeader
- object(optional): properties arename
: header nameregex
: regex to valid headererror
: throw the error if the validation is failed
validateCookies
- object(optional): the usage is as same as validateHeaderremoveQueryString
- 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()
}
})
to start the express server