Global

Methods

WRestapi(opt)

Description:
  • 建立http API伺服器

Source:
Parameters:
Name Type Description
opt Object

輸入設定參數物件

Properties
Name Type Attributes Default Description
serverHapi Object <optional>
null

輸入hapi伺服器物件,若提供,本服務將使用serverHapi.route自動加入apis。預設null

port Integer <optional>
8080

輸入API伺服器所在port,預設8080

docFolder String <optional>
'swdoc'

輸入swagger伺服器檔案所在資料夾字串,預設'swdoc',若檔案被誤刪可解壓縮[swdoc.7z]重置

apiParent String <optional>
'api'

輸入網址api所在名稱字串,預設'api'

funcs Object <optional>
{}

輸入伺服器端供使用者端呼叫之函數物件,各key為函數名稱,對應value為函數本體。各函數之輸入需為單一物件,而各函數回傳皆為Promise,可通過resolve與reject回傳結果,預設{}

routes Array <optional>
[]

輸入伺服器額外掛載routes陣列,預設[]

token String <optional>
''

輸入呼叫api時的預設金鑰字串,預設''

proc function <optional>
null

輸入處理api函數,預設null

routesToAPI(routesopt, apiParentopt, procopt) → {Array}

Description:
  • 由Routes陣列資料轉hapi的API資料陣列

Source:
Parameters:
Name Type Attributes Default Description
routes Array <optional>
[]

輸入需自動產製的routes資料陣列,每個元素需有'apiName'欄位,其值給予表名字串,'props'欄位,其值給予欄位物件,預設[]

apiParent String <optional>
'api'

輸入api上層路徑字串,預設'api'

proc function <optional>
() => {}

輸入各api處理函數,prop會傳入method(API method),apiName(表名),propName(指定欄位名稱),propValue(指定欄位值),payload(post時數據),req(hapi的req),res(hapi的res),pm(回傳用Promise),處理完畢後成功時呼叫pm.resolve回傳,失敗時呼叫pm.reject回傳,預設()=>{}

Returns:

回傳hapi的API資料陣列

Type
Array

routesToSwagger(hostopt, apiParentopt, routesopt) → {Object}

Description:
  • 由Routes陣列資料轉Swagger的設定物件

Source:
Parameters:
Name Type Attributes Default Description
host String <optional>
'localhost:8080'

輸入伺服器所在host字串,預設'localhost:8080'

apiParent String <optional>
'api'

輸入api上層路徑字串,預設'api'

routes Array <optional>
[]

輸入Routes陣列,每個物件皆需要有表名字串'apiName'、主鍵名字串'pk'、物件所屬欄位物件'props',預設[]

Returns:

回傳Swagger的設定物件

Type
Object