summary refs log tree commit diff
path: root/src/index.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-06 17:08:08 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-06 17:08:08 +0100
commit471d1d6b28f8a6b62680408756e389e8a0b71be0 (patch)
treef95518dd3e846734feaeee613aa3f37f43dcde62 /src/index.ts
parentuntrack DS_Store (diff)
downloadserver-471d1d6b28f8a6b62680408756e389e8a0b71be0.tar.xz
:sparkles: Base Server
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts47
1 files changed, 6 insertions, 41 deletions
diff --git a/src/index.ts b/src/index.ts

index 45374721..b267bbfb 100644 --- a/src/index.ts +++ b/src/index.ts
@@ -1,43 +1,8 @@ -import WebSocket from "ws"; -import DB from "./extras/Database"; -import { message_dev } from "./assets/datastru"; -import { v4 } from "uuid"; +process.on("uncaughtException", console.error); +process.on("unhandledRejection", console.error); +setTimeout(() => {}, 100000000); -class Server { - db: any; - constructor() { - this.db = DB; - } +import { Server } from "./Server"; - async listen(): Promise<void> { - await this.db.init(); - const wss = new WebSocket.Server({ port: 8080 }); - - wss.on("connection", (ws) => { - ws.on("message", async (msg: any) => { - const message: message_dev = msg; - - if (message.req_type) { - switch (message.req_type) { - case "new_auth": - const token = v4(); - await this.db.data.auth.push({ token }); - return ws.send({ new_token: token }); - case "check_auth": - if (!message.token) { - return ws.send({ error: "token not providen" }); - } - return this.db.data.auth({ token: message.token }).get(); - } - } else { - ws.send({ error: "req_type not providen" }); - } - }); - - ws.send("connected"); - }); - } -} - -const s = new Server(); -s.listen(); +const server = new Server(); +server.listen();