mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 04:52:40 +00:00
fix check client version middleware to stop checking outside calls
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
import packageJSON from '../../package.json' with { type: "json" };
|
import packageJSON from '../../package.json' with { type: "json" };
|
||||||
const version = packageJSON.version;
|
|
||||||
|
|
||||||
//This should be only for internal calls, but right now prevents spam api calls, this should be done with a proper cors policy
|
export default (req, res, next) => {
|
||||||
|
const origin = req.get('Origin');
|
||||||
|
const sameSite = req.get('Host');
|
||||||
|
|
||||||
export default (req, res, next)=>{
|
if (origin && origin !== `http://${sameSite}` && origin !== `https://${sameSite}`) {
|
||||||
const userVersion = req.get('Homebrewery-Version');
|
return next(); // Skip version check if the request is from another site, like naturalcrit.com
|
||||||
|
}
|
||||||
|
|
||||||
if(userVersion != version) {
|
const userVersion = req.get('Homebrewery-Version');
|
||||||
return res.status(412).send({
|
const version = packageJSON.version;
|
||||||
message : `Client version ${userVersion} is out of date. Please save your changes elsewhere and refresh to pick up client version ${version}.`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
if (userVersion !== version) {
|
||||||
|
return res.status(412).send({
|
||||||
|
message: `Client version ${userVersion} is out of date. Please save your changes elsewhere and refresh to pick up client version ${version}.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user