Register page now uses api functions and can scan from vinmonopolet qr codes. Re-did formatting and styling on page.
This commit is contained in:
31
api/wineinfo.js
Normal file
31
api/wineinfo.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const router = express.Router();
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated"))
|
||||
|
||||
router.use((req, res, next) => {
|
||||
next();
|
||||
});
|
||||
|
||||
router.route("/wineinfo/:ean").get(async (req, res) => {
|
||||
const vinmonopoletResponse = await fetch("https://app.vinmonopolet.no/vmpws/v2/vmp/products/barCodeSearch/" + req.params.ean)
|
||||
.then(resp => resp.json())
|
||||
|
||||
if (vinmonopoletResponse.errors != null) {
|
||||
return vinmonopoletResponse.errors.map(error => {
|
||||
if (error.type == "UnknownProductError") {
|
||||
return res.status(404).json({
|
||||
message: error.message
|
||||
})
|
||||
} else {
|
||||
return next()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.send(vinmonopoletResponse);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user