forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (44 loc) · 1.37 KB
/
Copy pathindex.js
File metadata and controls
57 lines (44 loc) · 1.37 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
import { readFileSync } from 'fs'
import getPort from 'get-port'
import {
colors,
parseArgv,
} from './util.js'
import { createServer } from './server.js'
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
const arg = parseArgv()
async function startServer() {
try {
let { port = 8800 } = arg
port = Number(port)
port = await getPort({ port }).catch(_ => {
console.log(`端口 ${port} 被占用,正在寻找可用端口...`)
return getPort()
})
console.log(`doocs/md-cli v${packageJson.version}`)
console.log(`服务启动中...`)
const app = createServer(port)
app.listen(port, '127.0.0.1', () => {
console.log(`服务已启动:`)
console.log(`打开链接 ${colors.green(`http://127.0.0.1:${port}`)} 即刻使用吧~`)
console.log(``)
const { spaceId, clientSecret } = arg
if (spaceId && clientSecret) {
console.log(`${colors.green('✅ 云存储已配置,可通过自定义代码上传图片')}`)
}
})
process.once('SIGINT', () => {
console.log('\n服务器已关闭')
process.exit(0)
})
process.once('SIGTERM', () => {
console.log('\n服务器已关闭')
process.exit(0)
})
} catch (err) {
console.error('启动服务器失败:', err)
process.exit(1)
}
}
startServer()