renamed some stuff

This commit is contained in:
Daniel Hübleitner
2019-08-27 21:06:44 +02:00
parent f1eb9ec78e
commit 3a9aae3f7b
3 changed files with 6 additions and 185 deletions
-179
View File
@@ -1,179 +0,0 @@
'use strict'
import * as Logger from 'log4js'
import * as Knex from 'knex'
import { FrontblockApiClient, FrontblockApiConf } from 'frontblock';
import { AdminBase } from 'frontblock-generic/Admin';
import express = require('express');
import http = require('http');
import bsock = require('bsock');
import { promises as fs } from "fs"
import * as path from "path"
import { UpdateManager } from './UpdateManger';
import { FrontblockApi } from 'frontblock-generic/Api';
import { Plugin } from 'frontblock-generic/Plugin';
var exec = require('child-process-promise').exec;
Logger.configure({
appenders:
{
"admin": { type: 'stdout' },
//app: { type: 'file', filename: 'application.log' }
},
categories:
{
default: { appenders: [ 'admin' ], level: 'debug' }
}
})
const logger = Logger.getLogger("admin")
export type AdminConf = { httpPort: number}
/**
* FrontblockAdmin
*
* The customer-facing dynamic component of the customer backend
* Supports (un)loading plugins which will be communicated to its library component (See FrontblockLib.ts and the info() RPC)
*
* The list of available plugins is published via the frontblock API and downloaded via gitea-releases
*/
export class FrontblockAdmin extends AdminBase<AdminConf>{
private express
private httpServer
private io = bsock.createServer()
private wsServer = http.createServer()
private updateManager:UpdateManager = new UpdateManager(this)
constructor(runningPlugins: Plugin[] = []){
super(runningPlugins)
this.initialize()
}
getDefaultConfig(): { apiConf: FrontblockApiConf; } & AdminConf & { dbConf:Knex.Config; } {
return {
httpPort: 8080,
apiConf: {
apiHost: "api.testnet.frontblock.me",
apiKey: "",
apiPort: 10001,
tls: false
},
dbConf: {
client: 'sqlite3',
connection: {
filename: "./data/ApiClient.sqlite"
},
useNullAsDefault: true
}
}
}
protected makeApiClient(conf: FrontblockApiConf): FrontblockApi {
// @ts-ignore
if(this.apiClient) this.apiClient.disconnect()
this.apiClient = new FrontblockApiClient(conf)
// @ts-ignore
this.apiClient.connect()
return this.apiClient
}
private async initialize(){
this.addPlugin(this.updateManager)
await this.updateManager.updateAdmin()
await this.updateManager.updatePlatformDependencies()
await this.updateManager.updateDashboard()
await this.updateManager.updateFrontblockLib()
this.startWebsocket()
this.startWebserver()
}
private startWebserver(){
if(this.httpServer != null || this.express != null){
logger.warn("Webserver is already running")
return
}
let port:number = this.getConfig().httpPort
this.express = express()
this.express.use('/', express.static('static'))
/**
* get the compiled FrontendPlugins.js
*/
this.express.get('/plugins/:id'+".js", async (request, response) => {
const pth = path.resolve("plugins/"+request.params.id, "FrontendPlugin.js");
const file = await fs.readFile(pth)
const frontend = file.toString()
response.status(200)
response.set('Content-Type', 'application/javascript')
response.send(frontend)
})
/**
* serve the index.html from the static folder
*/
this.express.get("/", (request, response) => {
response.status(200)
response.sendFile('index.html');
})
/**
* redirect all the other traffic to the single
* page app to the main entry point from where
* a webpacked and rolled up index.html is serverd
* and angular takes over routing
*/
this.express.get("*", (request, response) => {
response.status(301)
response.redirect('/')
})
this.httpServer = new http.Server(this.express)
this.httpServer.listen(port, () => {
logger.info('Admin panel listening for HTTP on *'+port)
})
}
private stopWebserver(){
if(this.httpServer == null || this.express == null){
logger.warn("Webserver is not running")
return
}
this.httpServer.close()
this.httpServer = null
this.express = null
logger.info("Webserver stopped")
}
private startWebsocket(){
try{
this.io.attach(this.wsServer)
this.io.on('socket', (socket) => {
logger.info("New Websocket connection on port", socket.port)
const handleError = (e: any) => {
logger.info("Websocket closing", String(e))
socket.close()
}
socket.on('error', handleError)
this.initApis(socket)
})
logger.info('Admin websocket listening on *20000')
this.wsServer.listen(20000)
}catch(e){
logger.error(String(e))
}
}
}
process.on( 'SIGINT', function() {
logger.info( "Gracefully shutting down from SIGINT (Ctrl-C)" );
// some other closing procedures go here
process.exit( );
})
+5 -5
View File
@@ -5,21 +5,21 @@ var exec = require('child-process-promise').exec;
Logger.configure({
appenders:
{
"admin": { type: 'stdout' },
"main": { type: 'stdout' },
//app: { type: 'file', filename: 'application.log' }
},
categories:
{
default: { appenders: [ 'admin' ], level: 'debug' }
default: { appenders: [ 'main' ], level: 'debug' }
}
})
const logger = Logger.getLogger("admin")
const logger = Logger.getLogger("main")
logger.info("Checking npm dependencies...")
exec("npm i --prefix ./plugins knex@0.19.2 sqlite3@4.1.0").then(process => {
logger.debug(process.stdout)
const admin = require("./FrontblockAdmin").FrontblockAdmin
new admin()
const Admin = require("./Admin").FrontblockAdmin
new Admin()
})
+1 -1
View File
@@ -3,7 +3,7 @@ import { socketioRPC } from "frontblock-generic/RPC";
import { GitUpdater, RepoFolderStatus } from "./GitUpdater";
import { FrontblockCherryPicker } from "git-cherrypicker";
import * as Logger from 'log4js'
import { FrontblockAdmin } from "./FrontblockAdmin";
import { FrontblockAdmin } from "./Admin";
import { TableDefiniton } from "frontblock-generic/Admin";
var exec = require('child-process-promise').exec;