-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (39 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict'
const fs = require('fs')
const worker = require('ddv-worker')
const logger = require('./lib/logger.js')
// 导出 expressWorker
module.exports = worker
var isServerStart = false
worker.serverStart = function serverStart (options, siteConfigFile) {
if (isServerStart) {
logger.error('Please do not start many times')
process.exit(-1)
return
}
isServerStart = true
if (!fs.existsSync(options.appPath)) {
logger.error('Options.appPath does not exist, please check')
logger.error(options.appPath)
process.exit(-1)
return
}
require('ddv-worker-express-ws')(options)
// 运行app
let fn = require(options.appPath)
if (typeof fn === 'function') {
fn(options, siteConfigFile)
}
// 监听服务 - Listen the server
worker.updateServerConf({
defaultListen: options.defaultListen,
listen: options.listen,
cpuLen: options.cpuLen
}).then(res => {
logger.log('listen updated success')
logger.log(res)
}, e => {
logger.log('listen updated fail')
logger.error(e)
})
}