From 0e136b62c8b93c97ef7a54bf11c3eea5f2f6af34 Mon Sep 17 00:00:00 2001 From: Killer Boss Original <73131550+killerbossoriginal@users.noreply.github.com> Date: Tue, 5 Jul 2022 15:10:58 +0200 Subject: [PATCH] log + auth --- index.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 45c7238..cc9d0a5 100644 --- a/index.js +++ b/index.js @@ -29,9 +29,11 @@ app.listen(client.config.port, app.use(express.static('public')); app.use(cors()); -async function authenticate(token) { +async function authenticate(token, what) { if (!client.config.auth.includes(token)) { - return; + response.send('ERROR - Not auth') + } else { + console.log(token + ' do '+ what) } } @@ -41,7 +43,7 @@ app.get('/api/:auth/database', alldata); function alldata(request, response) { var token = request.params.auth; - authenticate(token) + authenticate(token, 'alldata') response.send(elements); } @@ -51,16 +53,16 @@ app.get('/api/:auth/database/:element/', searchElement); async function searchElement(request, response) { var token = request.params.auth; - authenticate(token) - var word = request.params.element; + search = 'search '+ word + authenticate(token, search) + var elements = await db.get(word) if(elements) { var reply = elements; - } - else { + } else { var reply = { status:"Not Found" } @@ -75,20 +77,21 @@ app.get('/api/:auth/database/:element/set/:data', set); async function set(request, response) { var token = request.params.auth; - authenticate(token) - var element = request.params.element; var data = request.params.data; + + set = 'set '+element+' to '+data + authenticate(token, set) + await db.set(element, data) const res = await db.get(element) if(res) { var reply = res; - } - else { + } else { var reply = { status:"Not Found" } } response.send(reply); -} +} \ No newline at end of file