|
1
2
|
import chalk from 'chalk';
import Koa from 'koa';
|
vben
authored
|
3
|
// import inquirer from 'inquirer';
|
|
4
5
6
|
import staticServer from 'koa-static';
import portfinder from 'portfinder';
import { resolve } from 'path';
|
vben
authored
|
7
|
import { getIPAddress } from '../utils';
|
|
8
|
|
nebv
authored
|
9
|
// start server
|
|
10
11
12
13
14
|
const startApp = () => {
const port = 9680;
portfinder.basePort = port;
const app = new Koa();
|
vben
authored
|
15
|
app.use(staticServer(resolve(process.cwd(), 'dist')));
|
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
portfinder.getPort(async (err, port) => {
if (err) {
throw err;
} else {
app.listen(port, function () {
const empty = ' ';
const common = `The preview program is already running:
- LOCAL: http://localhost:${port}/
- NETWORK: http://${getIPAddress()}:${port}/
`;
console.log(chalk.cyan('\n' + empty + common));
});
}
});
};
|
vben
authored
|
33
|
startApp();
|