cli: set port as paramter
This commit is contained in:
parent
e8f22b16d3
commit
00cc673583
@ -30,9 +30,8 @@ function getIPAdress() {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function dev() {
|
export default async function dev(serverPort = 7777, resourcePort = 7778) {
|
||||||
const server = await createServer()
|
const server = await createServer(serverPort)
|
||||||
|
|
||||||
|
|
||||||
const cachedContents: Record<string, string> = {}
|
const cachedContents: Record<string, string> = {}
|
||||||
chokidar
|
chokidar
|
||||||
@ -123,7 +122,7 @@ export default async function dev() {
|
|||||||
console.log(`IP:${e}`);
|
console.log(`IP:${e}`);
|
||||||
qrcode.generate(e, { small: true });
|
qrcode.generate(e, { small: true });
|
||||||
});
|
});
|
||||||
createResServer();
|
await createResServer(resourcePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +25,14 @@ commander
|
|||||||
})
|
})
|
||||||
commander
|
commander
|
||||||
.command('dev')
|
.command('dev')
|
||||||
.action(async function () {
|
.option('--proxy', 'Link proxy')
|
||||||
await dev()
|
.action(async function (cmd, args) {
|
||||||
|
const [proxy] = args
|
||||||
|
if (proxy) {
|
||||||
|
console.log("Running in proxy mode", proxy)
|
||||||
|
} else {
|
||||||
|
await dev()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
commander
|
commander
|
||||||
.command('build')
|
.command('build')
|
||||||
@ -58,5 +64,10 @@ commander
|
|||||||
.action(async function (platform, cmd) {
|
.action(async function (platform, cmd) {
|
||||||
await run(platform);
|
await run(platform);
|
||||||
})
|
})
|
||||||
|
commander
|
||||||
|
.command('proxy')
|
||||||
|
.action(async function () {
|
||||||
|
await dev()
|
||||||
|
})
|
||||||
commander.parse(process.argv)
|
commander.parse(process.argv)
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ import fs from "fs"
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import http from "http";
|
import http from "http";
|
||||||
import { IncomingMessage, ServerResponse } from "http";
|
import { IncomingMessage, ServerResponse } from "http";
|
||||||
export async function createResServer() {
|
export async function createResServer(port: number) {
|
||||||
const port = 7778;
|
|
||||||
const server = http.createServer();
|
const server = http.createServer();
|
||||||
server.listen(port);
|
server.listen(port);
|
||||||
console.log(`resource server is listening on port ${port} !`.green);
|
console.log(`resource server is listening on port ${port} !`.green);
|
||||||
|
@ -12,12 +12,12 @@ export type MSG = {
|
|||||||
payload: { [index: string]: string }
|
payload: { [index: string]: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createServer() {
|
export async function createServer(port: number) {
|
||||||
let client: WebSocket | undefined = undefined;
|
let client: WebSocket | undefined = undefined;
|
||||||
let debug: WebSocket | undefined = undefined;
|
let debug: WebSocket | undefined = undefined;
|
||||||
let deviceId = 0
|
let deviceId = 0
|
||||||
let debugProcess: ChildProcess | undefined = undefined;
|
let debugProcess: ChildProcess | undefined = undefined;
|
||||||
const wss = new WebSocket.Server({ port: 7777 })
|
const wss = new WebSocket.Server({ port })
|
||||||
.on("connection", (ws, request) => {
|
.on("connection", (ws, request) => {
|
||||||
let thisDeviceId: string
|
let thisDeviceId: string
|
||||||
console.log('Connected', request.headers.host)
|
console.log('Connected', request.headers.host)
|
||||||
|
Reference in New Issue
Block a user