mirror of
https://github.com/zumbiepig/MineXLauncher.git
synced 2025-06-08 08:04:49 +00:00
add express server
This commit is contained in:
parent
5a5209cd46
commit
57b89f5bde
@ -1,15 +1,18 @@
|
||||
import eslint from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.strict, {
|
||||
export default tseslint.config(
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.strict,
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/ban-ts-comment': [
|
||||
'error',
|
||||
{
|
||||
'error', {
|
||||
'ts-expect-error': false,
|
||||
'ts-nocheck': false,
|
||||
'ts-check': true,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
63
index.ts
63
index.ts
@ -1 +1,62 @@
|
||||
console.log('Hello via Bun!');
|
||||
import { join } from 'path';
|
||||
import { env } from 'bun';
|
||||
import express, { json, urlencoded } from 'express';
|
||||
import chalk from 'chalk'
|
||||
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';
|
||||
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 debugLogger = debug('app:server');
|
||||
const isDev = env.NODE_ENV === 'development';
|
||||
|
||||
const app = express();
|
||||
app.enable('strict routing');
|
||||
|
||||
debugLogger('Booting server.');
|
||||
|
||||
app.use(
|
||||
helmet({
|
||||
contentSecurityPolicy: false,
|
||||
})
|
||||
);
|
||||
|
||||
app.use(morgan('combined'));
|
||||
app.use(json());
|
||||
app.use(urlencoded({ extended: false }));
|
||||
|
||||
app.use(cookieParser());
|
||||
|
||||
app.use(compression());
|
||||
|
||||
if (isDev) app.use(errorhandler());
|
||||
|
||||
app.use(serveFavicon(join(BASE_DIR, 'resources/images/icons/favicon.webp'), { maxAge: 86400 }));
|
||||
app.use(serveStatic(BASE_DIR));
|
||||
|
||||
app.use('/', indexRouter);
|
||||
|
||||
app.use(async (req, res, next) => {
|
||||
res.status(404).sendFile(join(BASE_DIR, '404.html'));
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(async (err, req, res, next) => {
|
||||
console.error(err.stack);
|
||||
res.status(500).send('500 Internal Server Error');
|
||||
next();
|
||||
});
|
||||
|
||||
app.listen(PORT, async () => {
|
||||
debugLogger('Server started.');
|
||||
console.log(chalk.green(`Server is running on port ${PORT}`));
|
||||
});
|
||||
|
19
package.json
19
package.json
@ -4,17 +4,32 @@
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "bun run ./index.ts",
|
||||
"start": "NODE_ENV=production bun run ./index.ts",
|
||||
"dev": "NODE_ENV=development DEBUG=app:* bun --watch run ./index.ts",
|
||||
"lint": "eslint ./src/",
|
||||
"lint:fix": "eslint --fix ./src/",
|
||||
"build": "bun run lint; rm -rf ./public/resources/scripts/ ./public/assets.json; tsc; javascript-obfuscator ./public/resources/scripts/ --output ./public/resources/scripts/ --options-preset high-obfuscation; bun run ./build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/bun": "latest"
|
||||
"chalk": "^5.3.0",
|
||||
"compression": "^1.7.4",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"debug": "^4.3.6",
|
||||
"errorhandler": "^1.5.1",
|
||||
"express": "^4.19.2",
|
||||
"helmet": "^7.1.0",
|
||||
"morgan": "^1.10.0",
|
||||
"serve-favicon": "^2.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/bun": "^1.0.7",
|
||||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@types/bun": "^1.1.8",
|
||||
"@types/compression": "^1.7.5",
|
||||
"@types/debug": "^4.1.12",
|
||||
"@types/errorhandler": "^1.5.3",
|
||||
"@types/morgan": "^1.9.9",
|
||||
"@types/serve-favicon": "^2.5.7",
|
||||
"eslint": "^9.9.1",
|
||||
"javascript-obfuscator": "^4.1.1",
|
||||
"typescript-eslint": "^8.3.0"
|
||||
|
8
routes/index.ts
Normal file
8
routes/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Router } from 'express';
|
||||
const indexRouter = Router();
|
||||
|
||||
indexRouter.get('/', async (req, res) => {
|
||||
// router for future use
|
||||
});
|
||||
|
||||
export { indexRouter };
|
Loading…
x
Reference in New Issue
Block a user