add authentication

This commit is contained in:
Francesco Esposito 2019-02-20 12:48:32 +01:00
parent 7db4a15c1b
commit c1c8da512b
4 changed files with 24 additions and 1 deletions

View File

@ -2,7 +2,10 @@
"app": {
"name": "trackmyd-api",
"auth": {
"secret": "mysecret"
"users": {
"client1": "client1",
"client2": "client2"
}
},
"port": 3500
},

16
package-lock.json generated
View File

@ -111,6 +111,14 @@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
"requires": {
"safe-buffer": "5.1.2"
}
},
"bluebird": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
@ -687,6 +695,14 @@
}
}
},
"express-basic-auth": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/express-basic-auth/-/express-basic-auth-1.1.6.tgz",
"integrity": "sha512-fRh/UU2q/YhvY0/Pkzi3VcLyjIExveW2NOOnOGgO6yO0jKXt6zcKPVPWSrL8nlhlh+YEH5LOjz+CGFML5dJQNw==",
"requires": {
"basic-auth": "^2.0.1"
}
},
"external-editor": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz",

View File

@ -26,6 +26,7 @@
"body-parser": "^1.18.3",
"bunyan": "^1.8.12",
"express": "^4.16.4",
"express-basic-auth": "^1.1.6",
"mongoose": "^5.4.13"
}
}

View File

@ -1,10 +1,12 @@
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const basicAuth = require('express-basic-auth');
const config = require('./config');
const logger = require('./logger');
const apiRoutes = require('./apiRoutes');
const { db } = config;
const app = express();
const port = process.env.PORT || config.app.port;
@ -16,6 +18,7 @@ mongoose.set('useFindAndModify', false);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(basicAuth({ users: config.app.auth.users }));
app.use('/api', apiRoutes);