mirror of
https://github.com/zumbiepig/MineXLauncher.git
synced 2025-06-08 08:04:49 +00:00
.
This commit is contained in:
parent
f887110b3c
commit
d554212037
@ -30,7 +30,7 @@
|
|||||||
"@tsconfig/strictest": "^2.0.5",
|
"@tsconfig/strictest": "^2.0.5",
|
||||||
"@types/bun": "^1.1.9",
|
"@types/bun": "^1.1.9",
|
||||||
"@types/compression": "^1.7.5",
|
"@types/compression": "^1.7.5",
|
||||||
"@types/debug": "^4.1.12",
|
"@types/cookie-parser": "^1.4.7",
|
||||||
"@types/errorhandler": "^1.5.3",
|
"@types/errorhandler": "^1.5.3",
|
||||||
"@types/eslint-config-prettier": "^6.11.3",
|
"@types/eslint-config-prettier": "^6.11.3",
|
||||||
"@types/eslint__js": "^8.42.3",
|
"@types/eslint__js": "^8.42.3",
|
||||||
@ -40,7 +40,6 @@
|
|||||||
"@types/pako": "^2.0.3",
|
"@types/pako": "^2.0.3",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"@types/serve-favicon": "^2.5.7",
|
"@types/serve-favicon": "^2.5.7",
|
||||||
"debug": "^4.3.7",
|
|
||||||
"errorhandler": "^1.5.1",
|
"errorhandler": "^1.5.1",
|
||||||
"eslint": "^9.10.0",
|
"eslint": "^9.10.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
39
server.ts
39
server.ts
@ -1,12 +1,16 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { env } from 'bun';
|
|
||||||
import express, { json, urlencoded } from 'express';
|
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
|
import express, {
|
||||||
|
json,
|
||||||
|
urlencoded,
|
||||||
|
type Request,
|
||||||
|
type Response,
|
||||||
|
type NextFunction,
|
||||||
|
} from 'express';
|
||||||
|
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import cookieParser from 'cookie-parser';
|
import cookieParser from 'cookie-parser';
|
||||||
import debug from 'debug';
|
|
||||||
import errorhandler from 'errorhandler';
|
|
||||||
import helmet from 'helmet';
|
import helmet from 'helmet';
|
||||||
import morgan from 'morgan';
|
import morgan from 'morgan';
|
||||||
import serveFavicon from 'serve-favicon';
|
import serveFavicon from 'serve-favicon';
|
||||||
@ -15,16 +19,13 @@ import serveStatic from 'serve-static';
|
|||||||
import { indexRouter } from './routes/index.ts';
|
import { indexRouter } from './routes/index.ts';
|
||||||
|
|
||||||
const BASE_DIR = join(import.meta.dir, 'public');
|
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 = process.env.NODE_ENV === 'development';
|
||||||
const isDev = env.NODE_ENV === 'development';
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.enable('strict routing');
|
app.enable('strict routing');
|
||||||
|
|
||||||
debugLogger('Booting server.');
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
helmet({
|
helmet({
|
||||||
contentSecurityPolicy: false,
|
contentSecurityPolicy: false,
|
||||||
@ -38,8 +39,7 @@ app.use(urlencoded({ extended: false }));
|
|||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
|
if (isDev) app.use((await import('errorhandler')).default());
|
||||||
if (isDev) app.use(errorhandler());
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
serveFavicon(join(BASE_DIR, 'resources/images/icons/favicon.webp'), {
|
serveFavicon(join(BASE_DIR, 'resources/images/icons/favicon.webp'), {
|
||||||
@ -50,23 +50,22 @@ app.use(serveStatic(BASE_DIR));
|
|||||||
|
|
||||||
app.use('/', indexRouter);
|
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'));
|
res.status(404).sendFile(join(BASE_DIR, '404.html'));
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(async (err, req, res, next) => {
|
app.use((err: Error, _req: Request, res: Response, next: NextFunction) => {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
res.status(500).send('500 Internal Server Error');
|
res.status(500).send('500 Internal Server Error');
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
// push for the update dev
|
|
||||||
app
|
app
|
||||||
.listen(PORT, async () => {
|
.listen(PORT, () =>
|
||||||
debugLogger('Server started.');
|
console.log(chalk.green(`Server is running on port ${PORT}`)),
|
||||||
console.log(chalk.green(`Server is running on port ${PORT}`));
|
)
|
||||||
})
|
.on('error', (error: NodeJS.ErrnoException) => {
|
||||||
.on('error', (error) => {
|
|
||||||
if (error.code === 'EADDRINUSE') {
|
if (error.code === 'EADDRINUSE') {
|
||||||
console.error(
|
console.error(
|
||||||
chalk.red('EADDRINUSE') +
|
chalk.red('EADDRINUSE') +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user