|
@@ -14,13 +14,14 @@ import cors from 'cors'
|
|
|
|
|
|
|
|
const app = express();
|
|
const app = express();
|
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.json());
|
|
|
-app.use(basicAuth({
|
|
|
|
|
- users: { admin: 'superPasswd' },
|
|
|
|
|
- challenge: true
|
|
|
|
|
-}));
|
|
|
|
|
|
|
|
|
|
//TODO is cors package necesary? basic middleware could suffice
|
|
//TODO is cors package necesary? basic middleware could suffice
|
|
|
app.use(cors()); //TODO: set only safe origins
|
|
app.use(cors()); //TODO: set only safe origins
|
|
|
|
|
+app.use(basicAuth({
|
|
|
|
|
+ users: { admin: 'superPasswd' }
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const asyncExec = util.promisify(exec);
|
|
const asyncExec = util.promisify(exec);
|
|
|
|
|
|
|
@@ -38,13 +39,13 @@ app.get("/", (req, res) => {
|
|
|
res.send("Chain4All Blockchain service");
|
|
res.send("Chain4All Blockchain service");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-app.post("/price", (req, res) => {
|
|
|
|
|
- if (req.body && req.body.extent) {
|
|
|
|
|
- res.send({ price: getPrice(req.body.extent) });
|
|
|
|
|
|
|
+app.post("/price", (req, res) => { //add caching of same requests
|
|
|
|
|
+ if (req.body && req.body.area) {
|
|
|
|
|
+ res.send({ price: getPrice(req.body.area) });
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
res.status(400);
|
|
res.status(400);
|
|
|
- throw Error(JSON.stringify({ error: { name: "Error, request has no body with \"extent\" property!" } }));
|
|
|
|
|
|
|
+ throw Error(JSON.stringify({ error: { name: "Error, request has no body with \"area\" property!" } }));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -129,8 +130,8 @@ function getArea(extent: Array<Array<number>>): number {
|
|
|
return height * width;
|
|
return height * width;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function getPrice(extent: Array<Array<number>>): number {
|
|
|
|
|
- return getArea(extent) * PRICE_MODIFIER;
|
|
|
|
|
|
|
+function getPrice(area: number) : number {
|
|
|
|
|
+ return area * PRICE_MODIFIER;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function errorMiddleware(err: any, req: any, res: any, next: any): void { //TODO: add custom Exception class
|
|
function errorMiddleware(err: any, req: any, res: any, next: any): void { //TODO: add custom Exception class
|