1
0
mirror of https://github.com/ZeroCatDev/ClassworksKV.git synced 2025-07-01 20:09:23 +00:00

22 lines
570 B
JavaScript

import { siteKey } from "../config.js";
import AppError from "../utils/errors.js";
const checkSiteKey = (req, res, next) => {
const providedKey = req.headers['x-site-key'];
if (!siteKey) {
return next();
}
if (!providedKey || providedKey !== siteKey) {
const error = AppError.createError(
AppError.HTTP_STATUS.UNAUTHORIZED,
"此服务器已开启站点密钥验证,请在请求头中添加 x-site-key 以继续访问"
);
return res.status(error.statusCode).json(error);
}
next();
};
export default checkSiteKey;