From 0ccf73bc2b3e979a3401a9d8b5eae77992a00373 Mon Sep 17 00:00:00 2001 From: darker Date: Sat, 19 Feb 2022 18:37:13 +0100 Subject: [PATCH] feat/header json (#2) * feat: add content-type header as json on returns * feat: just construct a data before return it * docker: build with cache always * json: removed the old setter --- index.js | 20 ++++++++++---------- package.json | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 1be4764..feb194d 100644 --- a/index.js +++ b/index.js @@ -127,34 +127,34 @@ app.post(`${BASE_ROUTE}/drop/:project/:database/:collection`, async (req, res) = // A simple ping for checking if the service is up // curl /api/v1/ping app.get(`${BASE_ROUTE}/ping`, async (req, res) => { - res.json({ + const data = { "status": "success", "server-ip": req.hostname, "version": `GitRowsPack-Api-${version}`, - "message": `Welcome to the GitRowsPack shell. -For interactive help, type "help". -For more comprehensive documentation, see - https://github.com/Sanix-Darker/gitrowspack-api` - }); + "message": `Welcome to the GitRowsPack shell. For interactive help, type "help". For more comprehensive documentation, see https://github.com/Sanix-Darker/gitrowspack-api` + } + res.json(data); }); // A simple endpoint to get the list of databases // curl /api/v1/databases app.get(`${BASE_ROUTE}/:project/databases`, async (req, res) => { - res.json({ + const data = { "project": req.params.project, "databases": await gitrows.getDatabases(req.params.project) - }); + } + res.json(data); }); // A simple endpoint to get the list of databases // curl /api/v1/collections app.get(`${BASE_ROUTE}/:project/:database/collections`, async (req, res) => { - res.json({ + const data = { "project": req.params.project, "database": req.params.database, "collections": await gitrows.getCollections(req.params.project, req.params.database) - }); + } + res.json(data); }); diff --git a/package.json b/package.json index dc6d85a..e320d10 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "scripts": { "dev": "nodemon index.js", "start": "node index.js", - "docker-build": "docker build --no-cache -t sanixdarker/gitrowspack-api:latest -f Dockerfile .", - "docker-build-cache": "docker build -t sanixdarker/gitrowspack-api:latest -f Dockerfile .", + "docker-build": "docker build -t sanixdarker/gitrowspack-api:latest -f Dockerfile .", "docker-run": "docker run --env-file .env -it --rm -p 3030:3030 sanixdarker/gitrowspack-api:latest" }, "repository": {