| 
									
										
										
										
											2024-07-18 21:55:26 +03:00
										 |  |  | import express from "express"; | 
					
						
							|  |  |  | import path from "path"; | 
					
						
							|  |  |  | import favicon from "serve-favicon"; | 
					
						
							|  |  |  | import cookieParser from "cookie-parser"; | 
					
						
							|  |  |  | import helmet from "helmet"; | 
					
						
							|  |  |  | import compression from "compression"; | 
					
						
							| 
									
										
										
										
											2024-07-19 00:18:35 +03:00
										 |  |  | import { fileURLToPath } from "url"; | 
					
						
							|  |  |  | import { dirname } from "path"; | 
					
						
							| 
									
										
										
										
											2024-07-18 21:35:17 +03:00
										 |  |  | import sessionParser from "./routes/session_parser.js"; | 
					
						
							|  |  |  | import utils from "./services/utils.js"; | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | import assets from "./routes/assets.js"; | 
					
						
							|  |  |  | import routes from "./routes/routes.js"; | 
					
						
							|  |  |  | import custom from "./routes/custom.js"; | 
					
						
							|  |  |  | import error_handlers from "./routes/error_handlers.js"; | 
					
						
							| 
									
										
										
										
											2024-07-19 00:34:37 +03:00
										 |  |  | import { startScheduledCleanup } from "./services/erase.js"; | 
					
						
							| 
									
										
										
										
											2024-07-19 00:47:09 +03:00
										 |  |  | import sql_init from "./services/sql_init.js"; | 
					
						
							| 
									
										
										
										
											2023-05-07 15:23:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | await import('./services/handlers'); | 
					
						
							|  |  |  | await import('./becca/becca_loader'); | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | const app = express(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 00:18:35 +03:00
										 |  |  | const scriptDir = dirname(fileURLToPath(import.meta.url)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 00:47:09 +03:00
										 |  |  | // Initialize DB
 | 
					
						
							|  |  |  | sql_init.initializeDb(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | // view engine setup
 | 
					
						
							| 
									
										
										
										
											2024-07-19 00:18:35 +03:00
										 |  |  | app.set('views', path.join(scriptDir, 'views')); | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | app.set('view engine', 'ejs'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-22 19:29:58 +02:00
										 |  |  | if (!utils.isElectron()) { | 
					
						
							|  |  |  |     app.use(compression()); // HTTP compression
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-08-20 17:30:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 21:56:20 +03:00
										 |  |  | app.use(helmet({ | 
					
						
							| 
									
										
										
										
											2022-01-12 19:32:23 +01:00
										 |  |  |     hidePoweredBy: false, // errors out in electron
 | 
					
						
							| 
									
										
										
										
											2022-05-18 22:56:29 +02:00
										 |  |  |     contentSecurityPolicy: false, | 
					
						
							|  |  |  |     crossOriginEmbedderPolicy: false | 
					
						
							| 
									
										
										
										
											2018-10-14 11:31:23 +02:00
										 |  |  | })); | 
					
						
							| 
									
										
										
										
											2017-10-24 22:04:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 20:47:41 +03:00
										 |  |  | app.use(express.text({ limit: '500mb' })); | 
					
						
							|  |  |  | app.use(express.json({ limit: '500mb' })); | 
					
						
							|  |  |  | app.use(express.raw({ limit: '500mb' })); | 
					
						
							|  |  |  | app.use(express.urlencoded({ extended: false })); | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | app.use(cookieParser()); | 
					
						
							| 
									
										
										
										
											2024-07-19 00:18:35 +03:00
										 |  |  | app.use(express.static(path.join(scriptDir, 'public/root'))); | 
					
						
							|  |  |  | app.use(`/manifest.webmanifest`, express.static(path.join(scriptDir, 'public/manifest.webmanifest'))); | 
					
						
							|  |  |  | app.use(`/robots.txt`, express.static(path.join(scriptDir, 'public/robots.txt'))); | 
					
						
							| 
									
										
										
										
											2017-11-30 23:50:42 -05:00
										 |  |  | app.use(sessionParser); | 
					
						
							| 
									
										
										
										
											2024-07-19 00:18:35 +03:00
										 |  |  | app.use(favicon(`${scriptDir}/../images/app-icons/win/icon.ico`)); | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | assets.register(app); | 
					
						
							|  |  |  | routes.register(app); | 
					
						
							|  |  |  | custom.register(app); | 
					
						
							|  |  |  | error_handlers.register(app); | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-28 12:23:11 -04:00
										 |  |  | // triggers sync timer
 | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | await import("./services/sync"); | 
					
						
							| 
									
										
										
										
											2017-10-21 21:10:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-28 12:23:11 -04:00
										 |  |  | // triggers backup timer
 | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | await import('./services/backup'); | 
					
						
							| 
									
										
										
										
											2017-10-28 12:23:11 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 22:16:26 -05:00
										 |  |  | // trigger consistency checks timer
 | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | await import('./services/consistency_checks'); | 
					
						
							| 
									
										
										
										
											2017-12-14 22:16:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  | await import('./services/scheduler'); | 
					
						
							| 
									
										
										
										
											2018-03-02 20:56:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-19 00:34:37 +03:00
										 |  |  | startScheduledCleanup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 21:35:23 +01:00
										 |  |  | if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2024-07-18 23:24:36 +03:00
										 |  |  |     (await import('@electron/remote/main')).initialize(); | 
					
						
							| 
									
										
										
										
											2021-11-18 21:35:23 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-11-16 22:43:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 21:50:12 +03:00
										 |  |  | export default app; |