ily.li/src/App.ts

89 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-04-23 18:07:55 +02:00
import Application from "wms-core/Application";
2020-10-05 13:38:03 +02:00
import Migration, {MigrationType} from "wms-core/db/Migration";
2020-04-23 18:07:55 +02:00
import CreateMigrationsTable from "wms-core/migrations/CreateMigrationsTable";
import CreateLogsTable from "wms-core/migrations/CreateLogsTable";
import ExpressAppComponent from "wms-core/components/ExpressAppComponent";
import NunjucksComponent from "wms-core/components/NunjucksComponent";
import MysqlComponent from "wms-core/components/MysqlComponent";
import LogRequestsComponent from "wms-core/components/LogRequestsComponent";
import RedisComponent from "wms-core/components/RedisComponent";
import ServeStaticDirectoryComponent from "wms-core/components/ServeStaticDirectoryComponent";
import MaintenanceComponent from "wms-core/components/MaintenanceComponent";
import MailComponent from "wms-core/components/MailComponent";
import SessionComponent from "wms-core/components/SessionComponent";
import RedirectBackComponent from "wms-core/components/RedirectBackComponent";
import FormHelperComponent from "wms-core/components/FormHelperComponent";
import CsrfProtectionComponent from "wms-core/components/CsrfProtectionComponent";
import WebSocketServerComponent from "wms-core/components/WebSocketServerComponent";
import HomeController from "./controllers/HomeController";
2020-05-05 15:26:28 +02:00
import AutoUpdateComponent from "wms-core/components/AutoUpdateComponent";
2020-10-05 13:38:03 +02:00
import packageJson = require('../package.json');
2020-04-23 18:07:55 +02:00
2020-06-27 17:20:06 +02:00
export default class App extends Application {
2020-10-05 13:38:03 +02:00
public constructor(
private readonly addr: string,
private readonly port: number,
) {
super(packageJson.version);
2020-04-23 18:07:55 +02:00
}
2020-10-05 13:38:03 +02:00
protected getMigrations(): MigrationType<Migration>[] {
2020-04-23 18:07:55 +02:00
return [
CreateMigrationsTable,
CreateLogsTable,
];
}
protected async init(): Promise<void> {
this.registerComponents();
this.registerWebSocketListeners();
this.registerControllers();
}
private registerComponents() {
const redisComponent = new RedisComponent();
const mysqlComponent = new MysqlComponent();
2020-10-05 13:38:03 +02:00
const expressAppComponent = new ExpressAppComponent(this.addr, this.port);
2020-04-23 18:07:55 +02:00
this.use(expressAppComponent);
this.use(new NunjucksComponent());
this.use(new LogRequestsComponent());
// Static files
this.use(new ServeStaticDirectoryComponent('public'));
this.use(new ServeStaticDirectoryComponent('node_modules/feather-icons/dist', '/icons'));
// Maintenance
this.use(new MaintenanceComponent(this, () => {
return redisComponent.canServe() && mysqlComponent.canServe();
}));
2020-05-05 15:26:28 +02:00
this.use(new AutoUpdateComponent());
2020-04-23 18:07:55 +02:00
// Services
this.use(mysqlComponent);
this.use(new MailComponent());
// Session
this.use(redisComponent);
this.use(new SessionComponent(redisComponent));
// Utils
this.use(new RedirectBackComponent());
this.use(new FormHelperComponent());
// Middlewares
this.use(new CsrfProtectionComponent());
// WebSocket server
this.use(new WebSocketServerComponent(this, expressAppComponent, redisComponent));
}
private registerWebSocketListeners() {
2020-10-05 13:38:03 +02:00
// WebSocket listeners
2020-04-23 18:07:55 +02:00
}
private registerControllers() {
this.use(new HomeController());
}
2020-10-05 13:38:03 +02:00
}