UNPKG

769 Btext/coffeescriptView Raw
1#处理项目中的可执行的文件
2_path = require 'path'
3_fs = require 'fs-extra'
4
5_utils = require './utils'
6_data = require './data'
7
8#响应JSON
9responseJSON = (res, data)->
10 res.statusCode = 200
11 res.setHeader "Content-Type", "application/json; charset=utf-8"
12 res.json data
13
14
15#处理可执行的路由
16module.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