More refactoring.

This commit is contained in:
Henning Dieterichs
2019-07-31 20:26:15 +02:00
parent e4e17c69b6
commit aa2dbc8719
4 changed files with 180 additions and 184 deletions

42
extension/src/Server.ts Normal file
View File

@@ -0,0 +1,42 @@
import { WebSocketStream } from "@hediet/typed-json-rpc-websocket";
import { AddressInfo } from "net";
import WebSocket = require("ws");
import { join } from "path";
import { ConnectionHandler } from "./ConnectionHandler";
import { Sources } from "./extension";
import * as express from "express";
import * as http from "http";
import * as serveStatic from "serve-static";
export class Server {
private server: http.Server;
constructor(sources: Sources) {
const app = express();
app.use(serveStatic(join(__dirname, "../ui/dist")));
this.server = app.listen();
const wss = new WebSocket.Server({ server: this.server });
wss.on("connection", ws => {
const stream = new WebSocketStream(ws);
new ConnectionHandler(sources, stream, this);
});
console.log(this.port);
}
public get indexUrl(): string {
return `http://localhost:${this.port}/index.html?serverPort=${
this.port
}`;
}
public get mainBundle(): string {
return `http://localhost:${this.port}/main.js`;
}
public get port(): number {
const httpPort = (this.server.address() as AddressInfo).port;
return httpPort;
}
}