Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ron-rookout committed Jul 16, 2024
1 parent f57614c commit 8f162ed
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/cors.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type {CorsOptions, CorsRequest} from "cors";
import * as cors from "cors";
import fetch from "node-fetch";
import {getStoreSafe} from "./explorook-store";
import { getStoreSafe } from "./explorook-store";


const LOCALHOST_ORIGIN = "https://localhost:8080";
const ROOKOUT_ORIGIN_REGEX = /^https:\/\/.*\.rookout(?:-dev)?\.com$/;
const DYNATRACE_ORIGIN_REGEX = /^https:\/\/.*\.dynatrace(?:labs)?\.com$/;

const ALLOW_CORS_OPTION: CorsOptions = {origin: true};
const DENY_CORS_OPTION: CorsOptions = {origin: false};
const ALLOW_CORS_OPTION: cors.CorsOptions = {origin: true};
const DENY_CORS_OPTION: cors.CorsOptions = {origin: false};


const verifiedOriginsCache = new Set([LOCALHOST_ORIGIN]);

const store = getStoreSafe();

const corsOptionsDelegate = async (req: CorsRequest, callback: (err: Error | null, options?: CorsOptions) => void) => {
const corsOptionsDelegate = async (req: cors.CorsRequest, callback: (err: Error | null, options?: cors.CorsOptions) => void) => {
try {
const shouldSkipDtVerification = store.get("skipDtVerification", false);
const origin = req.headers.origin;
if (verifiedOriginsCache.has(origin) || ROOKOUT_ORIGIN_REGEX.test(origin)) {
callback(null, ALLOW_CORS_OPTION);
Expand All @@ -29,7 +29,7 @@ const corsOptionsDelegate = async (req: CorsRequest, callback: (err: Error | nul
return;
}

const shouldSkipDtVerification = store.get("skipDtVerification", false);

if (shouldSkipDtVerification) {
callback(null, ALLOW_CORS_OPTION);
return;
Expand Down

0 comments on commit 8f162ed

Please sign in to comment.