change port mapping so i dont get rekt

This commit is contained in:
peter
2020-08-13 13:07:26 +02:00
parent 9638d500f5
commit e12bb72632
4 changed files with 25 additions and 19 deletions
+21 -15
View File
@@ -66,11 +66,18 @@ export class FrontworkAdmin
} }
async start() { async start() {
let port: number = this.config.getConfig().httpPort
await this.makeKnex() await this.makeKnex()
this.startWebsocket() const app = await this.makeExpress()
const httpServer = new http.Server(app)
await this.startWebsocket(httpServer)
httpServer.listen(port)
await this.attachAngularSSR(app)
getLogger('Admin#startWebsocket').debug("Webserver up on", port)
await Promise.all(this.frontworkComponents.map(c => c.initialize ? c.initialize() : undefined)) await Promise.all(this.frontworkComponents.map(c => c.initialize ? c.initialize() : undefined))
getLogger('Admin#start').debug(this.frontworkComponents.length + " components initialized") getLogger('Admin#start').debug(this.frontworkComponents.length + " components initialized")
await this.startWebserver()
} }
stop() { stop() {
@@ -106,7 +113,7 @@ export class FrontworkAdmin
.flatMap(exp => exp.getTableDefinitions()) .flatMap(exp => exp.getTableDefinitions())
} }
private startWebsocket() { private startWebsocket(httpServer: http.Server) {
this.rpcServer = new RPCServer([ this.rpcServer = new RPCServer([
...this.frontworkComponents, ...this.frontworkComponents,
{ {
@@ -119,24 +126,20 @@ export class FrontworkAdmin
], { ], {
errorHandler: (sock, err, rpc, args) => { errorHandler: (sock, err, rpc, args) => {
console.log(rpc, err); console.log(rpc, err);
} }
})
}).listen(20000) .attach(httpServer)
getLogger('Admin#startWebsocket').debug("Websocket up on", 20000)
} }
private async startWebserver() { private async makeExpress() {
if (this.httpServer != null || this.express != null) { if (this.httpServer != null || this.express != null) {
getLogger('Admin#startWebserver').warn("Webserver is already running") getLogger('Admin#startWebserver').warn("Webserver is already running")
return return
} }
let port: number = this.config.getConfig().httpPort
this.express = express() this.express = express()
const distFolder = "../../../../dist" const distFolder = "../../../../dist"
const ngExpressServer = Path.join(__dirname, distFolder, 'server.js')
this.express.get('*.*', (req, res) => { this.express.get('*.*', (req, res) => {
//console.log('*.*', req.path); //console.log('*.*', req.path);
@@ -153,20 +156,23 @@ export class FrontworkAdmin
res.status(404) res.status(404)
} }
}) })
return this.express
}
attachAngularSSR = async (express : express.Application) => {
const distFolder = "../../../../dist"
const ngExpressServer = Path.join(__dirname, distFolder, 'server.js')
let port: number = this.config.getConfig().httpPort
try { try {
const req = require(distFolder + "/server.js") const req = require(distFolder + "/server.js")
await req.attachExpress(this.express, './dist', getLogger('angularSSR#')) await req.attachExpress(express, './dist', getLogger('angularSSR#'))
getLogger('Admin#startWebserver').debug('Frontend from ' + ngExpressServer + " loaded") getLogger('Admin#startWebserver').debug('Frontend from ' + ngExpressServer + " loaded")
} catch (e) { } catch (e) {
getLogger('Admin#startWebserver').error(e) getLogger('Admin#startWebserver').error(e)
getLogger('Admin#startWebserver').warn("No angular SSR module was provided in " + ngExpressServer) getLogger('Admin#startWebserver').warn("No angular SSR module was provided in " + ngExpressServer)
getLogger('Admin#startWebserver').warn("This is not fatal, but your page will not render on *" + port) getLogger('Admin#startWebserver').warn("This is not fatal, but your page will not render on *" + port)
} }
this.express.listen(port, () => {
getLogger('Admin#startWebserver').info('Admin panel listening for HTTP on *' + port)
})
} }
private stopWebserver() { private stopWebserver() {
+2 -2
View File
@@ -144,10 +144,10 @@ export class UserManager
} }
}))) })))
const rankServer = await this.startRankServer(20001) const rankServer = await this.startRankServer(20002)
this.rankServer = { this.rankServer = {
server: rankServer, server: rankServer,
port: 20001 port: 20002
} }
//setInterval(this.checkExpiredSessions, 600_000) //setInterval(this.checkExpiredSessions, 600_000)
} }
@@ -132,7 +132,7 @@ export class ClientApiService implements IApiService{
} }
try{ try{
let conn = new RPCSocket<FrontcraftIfc>(20000, window.location.hostname) let conn = new RPCSocket<FrontcraftIfc>(8080, window.location.hostname)
conn.on('close', async () => { conn.on('close', async () => {
}) })
@@ -83,7 +83,7 @@ export class ServerApiService implements IApiService {
} }
try { try {
let conn = new RPCSocket<FrontcraftIfc>(20000, window.location.hostname) let conn = new RPCSocket<FrontcraftIfc>(8080, window.location.hostname)
conn.on('close', async () => { conn.on('close', async () => {
}) })