1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-08 03:44:49 +00:00
This commit is contained in:
zumbiepig 2024-09-12 15:06:20 -07:00
parent f887110b3c
commit d554212037
No known key found for this signature in database
GPG Key ID: 17C891BE28B953DE
3 changed files with 20 additions and 22 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -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",

View File

@ -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') +