Browse Source

add static basic auth

kunickyd 3 năm trước cách đây
mục cha
commit
a8712eed8a
1 tập tin đã thay đổi với 9 bổ sung2 xóa
  1. 9 2
      app.js

+ 9 - 2
app.js

@@ -2,9 +2,14 @@ import 'dotenv/config'
 import fetch from "node-fetch"
 import express from "express"
 import bodyParser from "body-parser"
+import basicAuth from "express-basic-auth"
 
 const app = express();
 app.use(bodyParser.json());
+app.use(basicAuth({
+    users : { 'admin' : 'superPasswd' },
+    challange : true
+}));
 
 const CHAIN4ALL_SERVICE_PORT = process.env.CHAIN4ALL_SERVICE_PORT || 3000;
 const IROHA_API_HOST = process.env.IROHA_API_HOST || "http://localhost";
@@ -163,13 +168,15 @@ function getPrice(extent) {
     return getArea(extent) * PRICE_MODIFIER;
 }
 
-function error(err, req, res, next) { //TODO: add custom Exception class
+function errorMiddleware(err, req, res, next) { //TODO: add custom Exception class
     console.log(err);
     res.status(500);
     res.send(err.message);
 }
 
-app.use(error);
+app.use(errorMiddleware);
+
+
 
 app.listen(CHAIN4ALL_SERVICE_PORT, () => {
     console.log(`Listening at http://localhost:${CHAIN4ALL_SERVICE_PORT}`)