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, () => {