-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (28 loc) · 768 Bytes
/
server.js
File metadata and controls
30 lines (28 loc) · 768 Bytes
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
/**
* @Author: Caven Chen
* @Date: 2024-04-26
*/
import express from 'express'
import portfinder from 'portfinder'
import fse from 'fs-extra'
import shell from 'shelljs'
import chalk from 'chalk'
export default function start() {
let dist = 'dist'
const server = express()
portfinder.setBasePort(8081)
fse.exists(dist, (exists) => {
if (exists) {
portfinder.getPort((err, port) => {
server.listen(port)
shell.echo('\nExamples running at: ')
shell.echo('- Local: ' + chalk.yellow(`http://localhost:${port}`))
shell.echo('\n')
server.use('/libs/', express.static(dist))
server.use(express.static('examples'))
})
} else {
shell.echo(chalk.red(`please run build first`))
}
})
}