diff --git a/packages/api/package.json b/packages/api/package.json index bfc74989..07398b67 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -14,6 +14,7 @@ "csv": "^5.3.2", "eslint": "^6.8.0", "express": "^4.17.1", + "express-basic-auth": "^1.2.0", "find-free-port": "^2.0.0", "fs-extra": "^8.1.0", "http": "^0.0.0", diff --git a/packages/api/src/main.js b/packages/api/src/main.js index 838d0883..e15ef032 100644 --- a/packages/api/src/main.js +++ b/packages/api/src/main.js @@ -1,4 +1,5 @@ const express = require('express'); +const basicAuth = require('express-basic-auth'); const bodyParser = require('body-parser'); const http = require('http'); const cors = require('cors'); @@ -29,6 +30,18 @@ function start(argument = null) { const server = http.createServer(app); socket.set(io(server)); + if (process.env.LOGIN && process.env.PASSWORD) { + app.use( + basicAuth({ + users: { + [process.env.LOGIN]: process.env.PASSWORD, + }, + challenge: true, + realm: 'DbGate Web App', + }) + ); + } + app.use(cors()); app.use(bodyParser.json()); diff --git a/yarn.lock b/yarn.lock index db0097f8..13849b32 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2489,6 +2489,13 @@ base@^0.11.1: mixin-deep "^1.2.0" pascalcase "^0.1.1" +basic-auth@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a" + integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg== + dependencies: + safe-buffer "5.1.2" + batch@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16" @@ -4779,6 +4786,13 @@ expect@^24.9.0: jest-message-util "^24.9.0" jest-regex-util "^24.9.0" +express-basic-auth@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/express-basic-auth/-/express-basic-auth-1.2.0.tgz#a1d40b07721376ba916e73571a60969211224808" + integrity sha512-iJ0h1Gk6fZRrFmO7tP9nIbxwNgCUJASfNj5fb0Hy15lGtbqqsxpt7609+wq+0XlByZjXmC/rslWQtnuSTVRIcg== + dependencies: + basic-auth "^2.0.1" + express@^4.17.1: version "4.17.1" resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"