More setup and an example componente

This commit is contained in:
Daniel Kluge
2023-10-16 18:29:16 +02:00
parent 2bf455b44a
commit 99fd86ff95
11 changed files with 1692 additions and 74 deletions
@@ -0,0 +1,49 @@
import type { Express } from "express";
import express from "express";
import { jsonization, types } from "@aas-core-works/aas-core3.0rc02-typescript";
import AASInterfaceServer from "../server";
import type { OnRequestCallback } from "../server";
import AASStore from "../aasStore";
type Config = {
bindName: string,
bindPort: number,
}
export default class HTTPInterfaceServer extends AASInterfaceServer<Config> {
public name: string = "HTTPInterfaceServer";
private app: Express = express();
private server: any = null;
private observers: any[] = [];
public constructor(config: Config, aas: types.Environment, onRequestCallback: OnRequestCallback) {
super(config, aas, onRequestCallback);
}
public prepare(): void {
const aas = AASStore.getInstance().getAll()[0];
this.app.use(express.json());
this.app.get("/aas", (_, res) => {
res.json(jsonization.toJsonable(aas));
});
}
public run(): void {
this.server = this.app.listen(this.config.bindPort, this.config.bindName, () => {
console.log(`Listening on ${this.config.bindName}:${this.config.bindPort}`);
});
}
public stop(): void {
if (this.server && this.server.close) this.server.close();
}
public notify(event: any): void {
}
protected findElementByRequest(request: string): any | null {
throw new Error("Method not implemented.");
}
}