2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import express from "express";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-05 02:44:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import bodyParser from "body-parser";
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-06 16:26:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { unknownEndpointHandler } from "@/src/middleware/middleware";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { requestLogger } from "@/src/middleware/morgenMiddleware";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-03 22:25:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { errorHandler } from "@/src/middleware/errorHandler";
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { apiRouter } from "@/src/routes/api";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { cacheRouter } from "@/src/routes/cache";
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-02 00:20:49 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { customRouter } from "@/src/routes/custom";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { dynamicController } from "@/src/routes/dynamic";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-05 02:44:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { payRouter } from "@/src/routes/pay";
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-02 00:20:49 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { statsRouter } from "@/src/routes/stats";
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-04 14:44:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { webuiRouter } from "@/src/routes/webui";
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const app = express();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-19 20:38:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use((req, _res, next) => {
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:53:35 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // 38.5.0 introduced "ezip" for encrypted body blobs and "e" for request verification only (encrypted body blobs with no application data).
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-19 20:38:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // The bootstrapper decrypts it for us but having an unsupported Content-Encoding here would still be an issue for Express, so removing it.
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:53:35 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (req.headers["content-encoding"] == "ezip" || req.headers["content-encoding"] == "e") {
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-19 20:38:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        req.headers["content-encoding"] = undefined;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2025-05-05 04:57:44 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // U18 uses application/x-www-form-urlencoded even tho the data is JSON which Express doesn't like.
							 | 
						
					
						
							
								
									
										
										
										
											2025-05-05 18:09:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // U17 sets no Content-Type at all, which Express also doesn't like.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!req.headers["content-type"] || req.headers["content-type"] == "application/x-www-form-urlencoded") {
							 | 
						
					
						
							
								
									
										
										
										
											2025-05-05 04:57:44 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        req.headers["content-type"] = "application/octet-stream";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-19 20:38:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    next();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.use(bodyParser.raw());
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-24 16:12:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use(express.json({ limit: "4mb" }));
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-22 10:00:10 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use(bodyParser.text({ limit: "4mb" }));
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-06 16:26:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use(requestLogger);
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.use("/api", apiRouter);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.use("/", cacheRouter);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.use("/custom", customRouter);
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-21 05:19:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use("/dynamic", dynamicController);
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.use("/:id/dynamic", dynamicController);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-05 02:44:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use("/pay", payRouter);
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-01 17:52:59 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use("/stats", statsRouter);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-04 14:44:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use("/", webuiRouter);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								app.use(unknownEndpointHandler);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-03 22:46:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								app.use(errorHandler);
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-19 15:22:48 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export { app };
							 |