LETS GO BABY
This commit is contained in:
@ -2,14 +2,29 @@ import { Elysia } from "elysia";
|
||||
import cors from "@elysiajs/cors";
|
||||
import { decorators } from "elysia-decorators";
|
||||
import { logger } from "@tqman/nice-logger";
|
||||
import { swagger } from '@elysiajs/swagger'
|
||||
import { rateLimit } from 'elysia-rate-limit'
|
||||
import { swagger } from "@elysiajs/swagger";
|
||||
import { rateLimit } from "elysia-rate-limit";
|
||||
import { RateLimitError } from "./error/rate-limit-error";
|
||||
import { helmet } from 'elysia-helmet';
|
||||
import { etag } from '@bogeychan/elysia-etag'
|
||||
import { helmet } from "elysia-helmet";
|
||||
import { etag } from "@bogeychan/elysia-etag";
|
||||
import AppController from "./controller/app.controller";
|
||||
import * as dotenv from "@dotenvx/dotenvx";
|
||||
import mongoose from "mongoose";
|
||||
import { Config } from "./common/config";
|
||||
import { setLogLevel } from "@typegoose/typegoose";
|
||||
import PlayerController from "./controller/player.controller";
|
||||
import { PlayerService } from "./service/player.service";
|
||||
|
||||
const app = new Elysia();
|
||||
// Load .env file
|
||||
dotenv.config({
|
||||
logLevel: "success",
|
||||
path: ".env",
|
||||
override: true,
|
||||
});
|
||||
|
||||
await mongoose.connect(Config.mongoUri!); // Connect to MongoDB
|
||||
setLogLevel("DEBUG");
|
||||
export const app = new Elysia();
|
||||
|
||||
/**
|
||||
* Custom error handler
|
||||
@ -50,33 +65,37 @@ app.use(
|
||||
/**
|
||||
* Rate limit (100 requests per minute)
|
||||
*/
|
||||
app.use(rateLimit({
|
||||
scoping: "global",
|
||||
duration: 60 * 1000,
|
||||
max: 100,
|
||||
skip: (request) => {
|
||||
let [ _, path ] = request.url.split("/"); // Get the url parts
|
||||
path === "" || path === undefined && (path = "/"); // If we're on /, the path is undefined, so we set it to /
|
||||
return path === "/"; // ignore all requests to /
|
||||
},
|
||||
errorResponse: new RateLimitError("Too many requests, please try again later"),
|
||||
}))
|
||||
app.use(
|
||||
rateLimit({
|
||||
scoping: "global",
|
||||
duration: 60 * 1000,
|
||||
max: 100,
|
||||
skip: request => {
|
||||
let [_, path] = request.url.split("/"); // Get the url parts
|
||||
path === "" || (path === undefined && (path = "/")); // If we're on /, the path is undefined, so we set it to /
|
||||
return path === "/"; // ignore all requests to /
|
||||
},
|
||||
errorResponse: new RateLimitError("Too many requests, please try again later"),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Security settings
|
||||
*/
|
||||
app.use(helmet({
|
||||
hsts: false, // Disable HSTS
|
||||
contentSecurityPolicy: false, // Disable CSP
|
||||
dnsPrefetchControl: true, // Enable DNS prefetch
|
||||
}))
|
||||
app.use(
|
||||
helmet({
|
||||
hsts: false, // Disable HSTS
|
||||
contentSecurityPolicy: false, // Disable CSP
|
||||
dnsPrefetchControl: true, // Enable DNS prefetch
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Controllers
|
||||
*/
|
||||
app.use(
|
||||
decorators({
|
||||
controllers: [AppController],
|
||||
controllers: [AppController, PlayerController],
|
||||
})
|
||||
);
|
||||
|
||||
@ -89,4 +108,9 @@ app.onStart(() => {
|
||||
console.log("Listening on port http://localhost:8080");
|
||||
});
|
||||
|
||||
/**
|
||||
* Start cronjobs
|
||||
*/
|
||||
PlayerService.initCronjobs();
|
||||
|
||||
app.listen(8080);
|
||||
|
Reference in New Issue
Block a user