More setup and an example componente
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user