summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-22 23:29:06 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-22 23:29:06 +0200
commit4528a96ded3f2023d193957a95ffbd070e4cfc30 (patch)
tree8ad86c56dbd32dbd85a6d4ec9ce06d950a8fb2b3 /src
parent:zap: :sparkles: prod multi threading (diff)
downloadserver-4528a96ded3f2023d193957a95ffbd070e4cfc30.tar.xz
prepare npm publish
Diffstat (limited to 'src')
-rw-r--r--src/Server.ts10
-rw-r--r--src/index.ts52
-rw-r--r--src/middlewares/index.ts10
-rw-r--r--src/start.ts33
-rw-r--r--src/test/rethink_test.ts.disabled (renamed from src/test/rethink_test.ts)0
-rw-r--r--src/util/Captcha.ts1
-rw-r--r--src/util/Config.ts6
7 files changed, 67 insertions, 45 deletions
diff --git a/src/Server.ts b/src/Server.ts

index 19a0fc5f..03222d4a 100644 --- a/src/Server.ts +++ b/src/Server.ts
@@ -13,21 +13,21 @@ import { BodyParser } from "./middlewares/BodyParser"; import { Router } from "express"; import fetch from "node-fetch"; -export interface DiscordServerOptions extends ServerOptions {} +export interface FosscordServerOptions extends ServerOptions {} declare global { namespace Express { interface Request { // @ts-ignore - server: DiscordServer; + server: FosscordServer; } } } -export class DiscordServer extends Server { - public options: DiscordServerOptions; +export class FosscordServer extends Server { + public options: FosscordServerOptions; - constructor(opts?: Partial<DiscordServerOptions>) { + constructor(opts?: Partial<FosscordServerOptions>) { // @ts-ignore super({ ...opts, errorHandler: false, jsonBody: false }); } diff --git a/src/index.ts b/src/index.ts
index 471bf90c..c6417126 100644 --- a/src/index.ts +++ b/src/index.ts
@@ -1,33 +1,19 @@ -process.on("uncaughtException", console.error); -process.on("unhandledRejection", console.error); - -import "missing-native-js-functions"; -import { config } from "dotenv"; -config(); -import { DiscordServer } from "./Server"; -import cluster from "cluster"; -import os from "os"; -const cores = os.cpus().length; - -if (cluster.isMaster && process.env.production == "true") { - console.log(`Primary ${process.pid} is running`); - - // Fork workers. - for (let i = 0; i < cores; i++) { - cluster.fork(); - } - - cluster.on("exit", (worker, code, signal) => { - console.log(`worker ${worker.process.pid} died, restart worker`); - cluster.fork(); - }); -} else { - var port = Number(process.env.PORT); - if (isNaN(port)) port = 1000; - - const server = new DiscordServer({ port }); - server.start().catch(console.error); - - // @ts-ignore - global.server = server; -} +export * from "./Server"; +export * from "./middlewares/"; +export * from "./schema/Ban"; +export * from "./schema/Channel"; +export * from "./schema/Guild"; +export * from "./schema/Invite"; +export * from "./schema/Message"; +export * from "./util/Captcha"; +export * from "./util/Config"; +export * from "./util/Constants"; +export * from "./util/Event"; +export * from "./util/instanceOf"; +export * from "./util/Event"; +export * from "./util/instanceOf"; +export * from "./util/Member"; +export * from "./util/RandomInviteID"; +export * from "./util/String"; +export * from "./util/User"; +export { check as checkPassword } from "./util/passwordStrength"; diff --git a/src/middlewares/index.ts b/src/middlewares/index.ts
index e3332f07..6a2993a7 100644 --- a/src/middlewares/index.ts +++ b/src/middlewares/index.ts
@@ -1,4 +1,6 @@ -import { Authentication } from "./Authentication"; -import { GlobalRateLimit } from "./GlobalRateLimit"; - -export { Authentication, GlobalRateLimit }; +export * from "./GlobalRateLimit"; +export * from "./Authentication"; +export * from "./BodyParser"; +export * from "./CORS"; +export * from "./ErrorHandler"; +export * from "./RateLimit"; diff --git a/src/start.ts b/src/start.ts new file mode 100644
index 00000000..11e15941 --- /dev/null +++ b/src/start.ts
@@ -0,0 +1,33 @@ +process.on("uncaughtException", console.error); +process.on("unhandledRejection", console.error); + +import "missing-native-js-functions"; +import { config } from "dotenv"; +config(); +import { FosscordServer } from "./Server"; +import cluster from "cluster"; +import os from "os"; +const cores = os.cpus().length; + +if (cluster.isMaster && process.env.production == "true") { + console.log(`Primary ${process.pid} is running`); + + // Fork workers. + for (let i = 0; i < cores; i++) { + cluster.fork(); + } + + cluster.on("exit", (worker, code, signal) => { + console.log(`worker ${worker.process.pid} died, restart worker`); + cluster.fork(); + }); +} else { + var port = Number(process.env.PORT); + if (isNaN(port)) port = 1000; + + const server = new FosscordServer({ port }); + server.start().catch(console.error); + + // @ts-ignore + global.server = server; +} diff --git a/src/test/rethink_test.ts b/src/test/rethink_test.ts.disabled
index d1470515..d1470515 100644 --- a/src/test/rethink_test.ts +++ b/src/test/rethink_test.ts.disabled
diff --git a/src/util/Captcha.ts b/src/util/Captcha.ts
index e69de29b..cb0ff5c3 100644 --- a/src/util/Captcha.ts +++ b/src/util/Captcha.ts
@@ -0,0 +1 @@ +export {}; diff --git a/src/util/Config.ts b/src/util/Config.ts
index 60d83e1a..1a038b1d 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts
@@ -16,7 +16,7 @@ export default { setAll: Config.setAll, }; -export interface RateLimit { +export interface RateLimitOptions { count: number; timespan: number; } @@ -62,8 +62,8 @@ export interface DefaultOptions { }; routes: { auth?: { - login?: RateLimit; - register?: RateLimit; + login?: RateLimitOptions; + register?: RateLimitOptions; }; channel?: {}; // TODO: rate limit configuration for all routes