From 8ace4a6356192ff9a2a6ce6fb7f6fe4a7ae40073 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Sat, 1 Jun 2024 19:14:23 +0200 Subject: [PATCH] commit --- .dockerignore | 2 ++ DOCKERFILE | 9 +++++++++ api/v1/auth/login.js | 4 ++-- api/v1/auth/register.js | 4 ++-- api/v1/games/getall.js | 8 +++++--- docker-compose.yml | 12 ++++++++++++ 6 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 DOCKERFILE create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fed401d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +package-lock.json +node_modules/ \ No newline at end of file diff --git a/DOCKERFILE b/DOCKERFILE new file mode 100644 index 0000000..1400d59 --- /dev/null +++ b/DOCKERFILE @@ -0,0 +1,9 @@ +FROM node:latest + +WORKDIR /app + +COPY . /app + +RUN npm i + +CMD ["npm", "run", "start"] \ No newline at end of file diff --git a/api/v1/auth/login.js b/api/v1/auth/login.js index b1fd774..a5dd307 100644 --- a/api/v1/auth/login.js +++ b/api/v1/auth/login.js @@ -12,11 +12,11 @@ router.post('/', async (req, res) => { const user = await getUser(username); if (!user[0]) { - return res.status(500).send({error: "wrong login informations"}); + return res.status(400).send({error: "wrong login informations"}); } if (!(sha256(password) == user[0].password)) { - return res.status(500).send({error: "wrong login informations"}); + return res.status(400).send({error: "wrong login informations"}); } res.status(200).send({message: "connection successful", token: jwt.sign({username: username, expiration: 20000}, process.env.JWTSecret)}); diff --git a/api/v1/auth/register.js b/api/v1/auth/register.js index 82e45ea..77dc990 100644 --- a/api/v1/auth/register.js +++ b/api/v1/auth/register.js @@ -9,13 +9,13 @@ router.post('/', async (req, res) => { const {username, name, lastname, password} = req.body; if (!username || !name || !lastname || !password) { - return res.status(500).send({error: "invalid request"}); + return res.status(400).send({error: "invalid request"}); } const user = await getUser(username); if (user[0]) { - return res.status(500).send({error: "user already exist"}); + return res.status(400).send({error: "user already exist"}); } await addUser(username, name, lastname, sha256(password)); diff --git a/api/v1/games/getall.js b/api/v1/games/getall.js index fe45686..a2efa79 100644 --- a/api/v1/games/getall.js +++ b/api/v1/games/getall.js @@ -8,12 +8,14 @@ const router = express.Router(); router.post('/', async (req, res) => { const {token} = req.body; - let user; + if (!token) { + return res.status(400).send({error: "invalid token"}); + } try { - user = jwt.verify(token, process.env.JWTSecret); + jwt.verify(token, process.env.JWTSecret); } catch { - return res.status(500).send({error: "invalid token"}); + return res.status(400).send({error: "invalid token"}); } const games = await getGames(); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3a22d83 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.1' + +services: + joclud_api: + build: + context: . + dockerfile: DOCKERFILE + restart: always + volumes: + - /full/path/to/bot:/app + ports: + - "3000:3000" \ No newline at end of file