()
| 94 | }); |
| 95 | |
| 96 | async function main() { |
| 97 | // load global configuration file |
| 98 | initSystemConfig(); |
| 99 | |
| 100 | if (systemConfig && systemConfig?.redisUrl?.length != 0) { |
| 101 | await RedisStorage.initialize(systemConfig.redisUrl); |
| 102 | Storage.setStorageType(Storage.TYPE.REDIS); |
| 103 | } |
| 104 | |
| 105 | initVersionManager(); |
| 106 | const VERSION = getVersion(); |
| 107 | |
| 108 | console.log(`______ _______________________ ___ |
| 109 | ___ |/ /_ ____/_ ___/__ |/ /_____ _____________ _______ _____________ |
| 110 | __ /|_/ /_ / _____ \\__ /|_/ /_ __ \`/_ __ \\ __ \`/_ __ \`/ _ \\_ ___/ |
| 111 | _ / / / / /___ ____/ /_ / / / / /_/ /_ / / / /_/ /_ /_/ // __/ / |
| 112 | /_/ /_/ \\____/ /____/ /_/ /_/ \\__,_/ /_/ /_/\\__,_/ _\\__, / \\___//_/ |
| 113 | /____/ |
| 114 | |
| 115 | + Copyright ${new Date().getFullYear()} MCSManager Dev <https://github.com/MCSManager> |
| 116 | + Version ${VERSION} |
| 117 | `); |
| 118 | |
| 119 | // Detect whether the configuration file is from an older version and update it if so. |
| 120 | versionAdapter.detectConfig(); |
| 121 | |
| 122 | checkBusinessMode(); |
| 123 | |
| 124 | // Initialize services |
| 125 | await SystemUser.initialize(); |
| 126 | await SystemRemoteService.initialize(); |
| 127 | |
| 128 | const app = new Koa({ |
| 129 | proxy: systemConfig?.reverseProxyMode || false, |
| 130 | proxyIpHeader: systemConfig?.reverseProxyHeader || "X-Real-IP" |
| 131 | }); |
| 132 | |
| 133 | // Listen for Koa errors |
| 134 | app.on("error", (error) => { |
| 135 | // Block all Koa framework level events |
| 136 | // When Koa is attacked by a short connection flood, it is easy for error messages to swipe the screen, which may indirectly affect the operation of some applications |
| 137 | }); |
| 138 | |
| 139 | app.use(preCheckMiddleware); |
| 140 | app.use( |
| 141 | koaBody({ |
| 142 | multipart: true, |
| 143 | parsedMethods: [ |
| 144 | HttpMethodEnum.GET, |
| 145 | HttpMethodEnum.PUT, |
| 146 | HttpMethodEnum.POST, |
| 147 | HttpMethodEnum.DELETE |
| 148 | ], |
| 149 | formidable: { |
| 150 | maxFileSize: 1024 * 1024 * 500, |
| 151 | maxFiles: 1 |
| 152 | }, |
| 153 | jsonLimit: "10mb", |
no test coverage detected