 
   #校验校验权限
 
-  apiRoot = "/api/"
-  mapping = [
-      #项目
-      path: "#{apiRoot}project"
-      biz: "project"
-    ,
-      #素材
-      path: "#{apiRoot}project/:project_id(\\d+)/asset"
-      ### paths
-      paths:
-        post: "post path"
-        get: "get path"
-      ###
-      biz: "asset"
-      methods:
-        post: "uploadFile"
-        delete: false
-        put: false
-    ,
-      #查看素材
-      path: "/asset/:project_id(\\d+)/:filename",
-      biz: "asset"
-      methods:
-        get: "readFile"
-        put: false,
-        post: false,
-        delete: false
-    ,
-      #issue
-      path: "#{apiRoot}project/:project_id(\\d+)/issue"
-      biz: "issue"
-    ,
-      #针对issue的评论
-      path: "#{apiRoot}issue/:issue_id(\\d+)/comment"
-      biz: "comment"
-    ,
-      #建立或者解除asset与issue的关系
-      path: "#{apiRoot}issue/:issue_id(\\d+)/asset"
-      biz: "asset_issue_relation"
-      methods:
-        put: false
-    ,
-      #更改issue的状态，仅能更新
-      path: "#{apiRoot}issue/status"
-      biz: "issue"
-      methods:
-        get: false,
-        delete: false,
-        post: false
-        put: "changeStatus"
-    ,
-      #获取项目状态，及修改项目状态的路由
-      path: "#{apiRoot}project/:project_id(\\d+)/status"
-      biz: "project"
-      methods:
-        get: "getStatus",
-        delete: false,
-        post: false
-        put: "changeStatus"
-    ,
-      #用户登录
-      path: "#{apiRoot}signup"
-      biz: "member"
-      methods:
-        post: "signUp"
-        put: false,
-        delete: false,
-        get: false,
-  ]
-
-  mapping.forEach (map)->
-    apiRouterTo app, map
+  _config.routers.forEach (router)->
+    apiRouter app, router
 
   app.get "*", response404
-
-  #require('fs').renameSync '/Users/conis/WorkStation/BHF/src/uploads/2692-10y4zi.png', '/Users/conis/WorkStation/BHF/src/assets/2692-10y4zi.png'
-  ###
-  return
-  mapping =
-    "project": "project"
-    "issue": "project/:project_id/issue"
-    "comment": "issue/:issue_id/comment"
-    "asset": "project/:project_id/asset"
-
-  for key, path of mapping
-    biz = require "./biz/#{key}"
-    apiRouter biz, path, app
-###
  路由
###
_ = require 'underscore'

#API的路由
apiRouter = (biz, path, app)->
  path = "/api/#{path}"
  #读取信息
  app.get "#{path}/:id?", (req, res, next)->
    data = req.query || {}
    #可能存在parentId
    #data.parent_id = req.params.parent_id
    data = _.extend data, req.params
    #data.id = req.params.id

    biz.find data, (err, results)->
      res.json results

  #增加数据
  app.post path, (req, res, next)->
    data = req.body || {}
    data = _.extend data, req.params

    #保存数据
    biz.save data, (err, new_id)->
      res.json {id: new_id}

  #更新数据
  app.put "#{path}/:id", (req, res, next)->

  #删除数据
  app.delete "#{path}/:id", (req, res, next)->

#获取crud的默认path
getPaths = (map)->
  paths = {}

  pathPuffix =

    delete: "/:id(\\d+)"

  ["post", "get", "put", "delete"].forEach (method)->
    path = (router.paths && router.paths[method]) || (()->
      #如果有fullPath，则返回fullPath，否则重新组装path
      return router.fullPath || "#{_config.rootAPI}#{router.path}#{pathPuffix[method]}"
    )()
    console.log path
    paths[method] = path    #"/api/#{path}"
  paths

apiRouter = (app, router)->
  biz = require "./biz/#{router.biz}"
  paths = getPaths(router)

  ["get", "post", "delete", "put"].forEach (method)->
    path = paths[method]
    #如果在map中，有指定业务逻辑的处理方法，则交给业务逻辑处理
    specialMethod = (router.methods || {})[method]
    #如果指定的方法为false，则不处理这个method
    return if specialMethod is false
    #由业务逻辑指定的处理处理
