From c53c5178552eb7d40c9451fe0b066c63d469a9a8 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Mon, 8 Jul 2024 20:37:02 +0200 Subject: [PATCH] Cleanup index.ts --- src/index.ts | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6314039..c6a99cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ import express from 'express'; import bodyParser from 'body-parser'; -import Database from './db/database'; import fs from 'fs'; import authenticateJWT from './lib/authenticateJWT'; @@ -9,46 +8,21 @@ const app = express(); app.use(bodyParser.urlencoded({extended : true})); app.use(bodyParser.json()); -// const db = new Database(); - -// type User = { -// username: string, -// password: string, -// role: string, -// xp: number -// }; - const routes = 'routes'; +app.all('*', (req, res, next) => { + console.log(`[${new Date().toLocaleString()}] ${req.method} ${req.url}`); + next(); +}); + fs.readdirSync(routes).forEach((file: string) => { const route = require(`./${routes}/${file}`); app.use(`/${file.split('.')[0]}`, route.default); }); - - - - - - - - -app.get('/', (req, res) => { - res.json({ message: 'Hello World!' }); -}); - - - app.get('/test', authenticateJWT, (req, res) => { //@ts-ignore - res.json({ code: 200, message: `O chuj, zalogowałeś się ${req.user.username}!` }); -}); - -app.get('/db', (req, res) => { - const db = new Database(); - db.query('INSERT INTO words VALUES (NULL, "kot", "猫", "animals", "neko")', []); - - res.sendStatus(200); + res.json({ code: 200, message: `Authorization successful for user ${req.user.username}!` }); }); app.listen(3000, () => {