Skip to content

rap模块及proxy模块支持restful风格的接口 #1

Description

@zhuping
/**
 * 判断请求url是否符合白名单
 */
Url.prototype._match = function (url) {
  var rules = this.rules
  var len = rules.length
  var flag

  for (var i = 0; i < len; i++) {
    var rule = rules[i]
    if (_.isFunction(rule)) {
      flag = rule(url)
    } else {
      flag = rule.test(url)
    }

    if (flag) {
      break
    }
  }

  return flag
}

如果是restful风格的接口或者是.html结尾的json接口,rule是个自定义的函数,但传递的参数url很难判断是json接口。如果是通过this.headers.accept.indexOf('application/json') === -1去判断能跟准确些

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions