cli: set port as paramter

This commit is contained in:
pengfei.zhou 2023-08-11 14:00:06 +08:00 committed by jingpeng
parent e8f22b16d3
commit 00cc673583
4 changed files with 19 additions and 10 deletions

View File

@ -30,9 +30,8 @@ function getIPAdress() {
return ret;
}
export default async function dev() {
const server = await createServer()
export default async function dev(serverPort = 7777, resourcePort = 7778) {
const server = await createServer(serverPort)
const cachedContents: Record<string, string> = {}
chokidar
@ -123,7 +122,7 @@ export default async function dev() {
console.log(`IP:${e}`);
qrcode.generate(e, { small: true });
});
createResServer();
await createResServer(resourcePort);
}

View File

@ -25,8 +25,14 @@ commander
})
commander
.command('dev')
.action(async function () {
await dev()
.option('--proxy', 'Link proxy')
.action(async function (cmd, args) {
const [proxy] = args
if (proxy) {
console.log("Running in proxy mode", proxy)
} else {
await dev()
}
})
commander
.command('build')
@ -58,5 +64,10 @@ commander
.action(async function (platform, cmd) {
await run(platform);
})
commander
.command('proxy')
.action(async function () {
await dev()
})
commander.parse(process.argv)

View File

@ -2,8 +2,7 @@ import fs from "fs"
import path from "path"
import http from "http";
import { IncomingMessage, ServerResponse } from "http";
export async function createResServer() {
const port = 7778;
export async function createResServer(port: number) {
const server = http.createServer();
server.listen(port);
console.log(`resource server is listening on port ${port} !`.green);

View File

@ -12,12 +12,12 @@ export type MSG = {
payload: { [index: string]: string }
}
export async function createServer() {
export async function createServer(port: number) {
let client: WebSocket | undefined = undefined;
let debug: WebSocket | undefined = undefined;
let deviceId = 0
let debugProcess: ChildProcess | undefined = undefined;
const wss = new WebSocket.Server({ port: 7777 })
const wss = new WebSocket.Server({ port })
.on("connection", (ws, request) => {
let thisDeviceId: string
console.log('Connected', request.headers.host)