2020-09-28 20:19:10 +08:00
|
|
|
import chalk from 'chalk';
|
|
|
|
import Koa from 'koa';
|
2020-10-26 21:45:43 +08:00
|
|
|
// import inquirer from 'inquirer';
|
2020-09-28 20:19:10 +08:00
|
|
|
import staticServer from 'koa-static';
|
|
|
|
import portfinder from 'portfinder';
|
|
|
|
import { resolve } from 'path';
|
2020-10-15 21:38:50 +08:00
|
|
|
import { getIPAddress } from '../utils';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2020-10-13 01:40:21 +08:00
|
|
|
// start server
|
2020-09-28 20:19:10 +08:00
|
|
|
const startApp = () => {
|
|
|
|
const port = 9680;
|
|
|
|
portfinder.basePort = port;
|
|
|
|
const app = new Koa();
|
|
|
|
|
2020-12-22 22:13:03 +08:00
|
|
|
app.use(staticServer(resolve(process.cwd(), 'dist')));
|
2020-09-28 20:19:10 +08:00
|
|
|
|
|
|
|
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));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-10-26 21:45:43 +08:00
|
|
|
startApp();
|