:sparkles: Base Server
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();
|