From 4528a96ded3f2023d193957a95ffbd070e4cfc30 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 22 Apr 2021 23:29:06 +0200 Subject: prepare npm publish --- src/Server.ts | 10 ++++---- src/index.ts | 52 ++++++++++++++------------------------- src/middlewares/index.ts | 10 +++++--- src/start.ts | 33 +++++++++++++++++++++++++ src/test/rethink_test.ts | 34 ------------------------- src/test/rethink_test.ts.disabled | 34 +++++++++++++++++++++++++ src/util/Captcha.ts | 1 + src/util/Config.ts | 6 ++--- 8 files changed, 101 insertions(+), 79 deletions(-) create mode 100644 src/start.ts delete mode 100644 src/test/rethink_test.ts create mode 100644 src/test/rethink_test.ts.disabled (limited to 'src') 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) { + constructor(opts?: Partial) { // @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 deleted file mode 100644 index d1470515..00000000 --- a/src/test/rethink_test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { r } from "rethinkdb-ts"; - -async function main() { - const connection = await r.connect({ port: 28015 }); - - const db = r.db("test"); - const cursor = await db - .table("guilds") - .get(0) - .changes({ squash: true }) - .map(function (row) { - return row("old_val") - .keys() - .setUnion(row("new_val").keys()) - .concatMap(function (key) { - return r.branch( - row("old_val")(key).ne(row("new_val")(key)).default(true), - [[key, row("new_val")(key).default(null)]], - [] - ); - }) - .coerceTo("object"); - }) - .run(connection); - - console.log("each"); - cursor.each(function (err, row) { - if (err) throw err; - console.log(row); - }); - console.log("eachend"); -} - -main(); diff --git a/src/test/rethink_test.ts.disabled b/src/test/rethink_test.ts.disabled new file mode 100644 index 00000000..d1470515 --- /dev/null +++ b/src/test/rethink_test.ts.disabled @@ -0,0 +1,34 @@ +import { r } from "rethinkdb-ts"; + +async function main() { + const connection = await r.connect({ port: 28015 }); + + const db = r.db("test"); + const cursor = await db + .table("guilds") + .get(0) + .changes({ squash: true }) + .map(function (row) { + return row("old_val") + .keys() + .setUnion(row("new_val").keys()) + .concatMap(function (key) { + return r.branch( + row("old_val")(key).ne(row("new_val")(key)).default(true), + [[key, row("new_val")(key).default(null)]], + [] + ); + }) + .coerceTo("object"); + }) + .run(connection); + + console.log("each"); + cursor.each(function (err, row) { + if (err) throw err; + console.log(row); + }); + console.log("eachend"); +} + +main(); 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 -- cgit 1.5.1