feat: bypass cors middleware on get requests

This commit is contained in:
Eli Bosley
2023-04-27 15:16:26 -04:00
parent c6271ca46c
commit 1e608c0aa8
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ const saveApiReport = async (pathToReport: string) => {
};
export const getLogs = async (req: Request, res: Response) => {
const apiKey = req.headers['x-api-key'];
const apiKey = req.headers['x-api-key'] || req.query.apiKey;
const logPath = getters.paths()['log-base'];
try {
await saveApiReport(join(logPath, 'report.json'));
+4
View File
@@ -24,6 +24,10 @@ export const originMiddleware = (
res: Response,
next: NextFunction
): void => {
if (req.method === 'GET' && req.query.apiKey && !req.headers.origin) {
// Bypass GET request headers on requests to the log endpoint
return next();
}
// Dev Mode Bypass
const origin = req.get('Origin')?.toLowerCase() ?? '';
const allowedOrigins = getAllowedOrigins();