1 |
|
2 | _path = require 'path'
|
3 | _fs = require 'fs-extra'
|
4 |
|
5 | _utils = require './utils'
|
6 | _data = require './data'
|
7 |
|
8 |
|
9 | responseJSON = (res, data)->
|
10 | res.statusCode = 200
|
11 | res.setHeader "Content-Type", "application/json; charset=utf-8"
|
12 | res.json data
|
13 |
|
14 |
|
15 |
|
16 | module.exports = (route, url, req, res, next)->
|
17 | file = _path.join _utils.options.workbench, route.url
|
18 |
|
19 | if not _fs.existsSync file
|
20 | error = "找不到可执行文件:#{file}"
|
21 | return req.end error
|
22 |
|
23 | silky =
|
24 | options: _utils.options
|
25 | config: _utils.options
|
26 | data: _data.whole
|
27 | responseJSON: responseJSON
|
28 |
|
29 |
|
30 |
|
31 | delete require.cache[require.resolve(file)]
|
32 | executeFile = require file
|
33 | executeFile req, res, next, silky |
\ | No newline at end of file |