diff --git a/bun.lockb b/bun.lockb index ce99cf4..645719c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 39de9b0..e523e77 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@tsconfig/strictest": "^2.0.5", "@types/bun": "^1.1.9", "@types/compression": "^1.7.5", - "@types/debug": "^4.1.12", + "@types/cookie-parser": "^1.4.7", "@types/errorhandler": "^1.5.3", "@types/eslint-config-prettier": "^6.11.3", "@types/eslint__js": "^8.42.3", @@ -40,7 +40,6 @@ "@types/pako": "^2.0.3", "@types/semver": "^7.5.8", "@types/serve-favicon": "^2.5.7", - "debug": "^4.3.7", "errorhandler": "^1.5.1", "eslint": "^9.10.0", "eslint-config-prettier": "^9.1.0", diff --git a/server.ts b/server.ts index 4ea167e..529d516 100644 --- a/server.ts +++ b/server.ts @@ -1,12 +1,16 @@ -// @ts-nocheck import { join } from 'path'; -import { env } from 'bun'; -import express, { json, urlencoded } from 'express'; import chalk from 'chalk'; + +import express, { + json, + urlencoded, + type Request, + type Response, + type NextFunction, +} from 'express'; + import compression from 'compression'; import cookieParser from 'cookie-parser'; -import debug from 'debug'; -import errorhandler from 'errorhandler'; import helmet from 'helmet'; import morgan from 'morgan'; import serveFavicon from 'serve-favicon'; @@ -15,16 +19,13 @@ import serveStatic from 'serve-static'; import { indexRouter } from './routes/index.ts'; const BASE_DIR = join(import.meta.dir, 'public'); -const PORT = env.PORT ?? 3000; +const PORT = process.env['PORT'] ?? 3000; -const debugLogger = debug('minexlauncher:server'); -const isDev = env.NODE_ENV === 'development'; +const isDev = process.env.NODE_ENV === 'development'; const app = express(); app.enable('strict routing'); -debugLogger('Booting server.'); - app.use( helmet({ contentSecurityPolicy: false, @@ -38,8 +39,7 @@ app.use(urlencoded({ extended: false })); app.use(cookieParser()); app.use(compression()); - -if (isDev) app.use(errorhandler()); +if (isDev) app.use((await import('errorhandler')).default()); app.use( serveFavicon(join(BASE_DIR, 'resources/images/icons/favicon.webp'), { @@ -50,23 +50,22 @@ app.use(serveStatic(BASE_DIR)); app.use('/', indexRouter); -app.use(async (req, res, next) => { +app.use((_req: Request, res: Response, next: NextFunction) => { res.status(404).sendFile(join(BASE_DIR, '404.html')); next(); }); -app.use(async (err, req, res, next) => { +app.use((err: Error, _req: Request, res: Response, next: NextFunction) => { console.error(err.stack); res.status(500).send('500 Internal Server Error'); next(); }); -// push for the update dev + app - .listen(PORT, async () => { - debugLogger('Server started.'); - console.log(chalk.green(`Server is running on port ${PORT}`)); - }) - .on('error', (error) => { + .listen(PORT, () => + console.log(chalk.green(`Server is running on port ${PORT}`)), + ) + .on('error', (error: NodeJS.ErrnoException) => { if (error.code === 'EADDRINUSE') { console.error( chalk.red('EADDRINUSE') +