2024-08-22 11:40:31 +02:00
|
|
|
import "dotenv/config";
|
|
|
|
import express from "express";
|
|
|
|
|
2025-01-29 16:49:34 +01:00
|
|
|
import { BACKUP_AUTO_RESTORE, configCheck, SERVER_PORT } from "./env.defaults";
|
2024-08-25 18:07:34 +02:00
|
|
|
configCheck();
|
|
|
|
|
2024-12-18 12:55:03 +01:00
|
|
|
import { PermissionObject } from "./type/permissionTypes";
|
2024-08-22 11:40:31 +02:00
|
|
|
declare global {
|
|
|
|
namespace Express {
|
|
|
|
export interface Request {
|
|
|
|
userId: string;
|
|
|
|
username: string;
|
2024-10-07 18:09:27 +02:00
|
|
|
isOwner: boolean;
|
2024-08-27 11:47:27 +02:00
|
|
|
permissions: PermissionObject;
|
2025-01-11 14:45:37 +01:00
|
|
|
isPWA: boolean;
|
2025-01-22 09:27:15 +01:00
|
|
|
isWebApiRequest: boolean;
|
2024-08-22 11:40:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
import { dataSource } from "./data-source";
|
2025-01-29 16:49:34 +01:00
|
|
|
import BackupHelper from "./helpers/backupHelper";
|
|
|
|
dataSource.initialize().then(async () => {
|
2025-01-29 18:10:41 +01:00
|
|
|
if ((BACKUP_AUTO_RESTORE as "true" | "false") == "true" && (await dataSource.createQueryRunner().hasTable("user"))) {
|
2025-01-29 16:49:34 +01:00
|
|
|
await BackupHelper.autoRestoreBackup().catch((err) => {
|
2025-02-03 16:34:49 +01:00
|
|
|
console.log(`${new Date().toISOString()}: failed auto-restoring database`, err);
|
2025-01-29 16:49:34 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2024-08-22 11:40:31 +02:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
import router from "./routes/index";
|
|
|
|
router(app);
|
2024-10-21 10:38:14 +02:00
|
|
|
app.listen(process.env.NODE_ENV ? SERVER_PORT : 5000, () => {
|
2025-01-29 16:49:34 +01:00
|
|
|
console.log(`${new Date().toISOString()}: listening on port ${process.env.NODE_ENV ? SERVER_PORT : 5000}`);
|
2024-08-22 11:40:31 +02:00
|
|
|
});
|
2024-09-04 14:01:22 +02:00
|
|
|
|
|
|
|
import schedule from "node-schedule";
|
|
|
|
import RefreshCommandHandler from "./command/refreshCommandHandler";
|
|
|
|
const job = schedule.scheduleJob("0 0 * * *", async () => {
|
2025-01-29 16:49:34 +01:00
|
|
|
console.log(`${new Date().toISOString()}: running Cron`);
|
2024-09-04 14:01:22 +02:00
|
|
|
await RefreshCommandHandler.deleteExpired();
|
2025-02-03 11:03:31 +01:00
|
|
|
await BackupHelper.createBackupOnInterval();
|
2024-09-04 14:01:22 +02:00
|
|
|
});
|