All files / src/Http util.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2039x   39x 39x 39x   39x       39x   6x 5x   1x        
import { ProviderError, ProviderFailure } from '@cardano-sdk/core';
 
export const ORIGIN = 'Origin';
export const CONTENT_TYPE = 'Content-Type';
export const APPLICATION_JSON = 'application/json';
 
export const getListen = (url: URL) => ({ host: url.hostname, port: Number.parseInt(url.port) });
 
type StaticOrigin = boolean | string | RegExp | (boolean | string | RegExp)[];
 
export const corsOptions = (allowedOrigins: Set<string>) => ({
  origin(requestOrigin: string | undefined, callback: (err: Error | null, options?: StaticOrigin) => void) {
    if (!requestOrigin || allowedOrigins.has(requestOrigin)) {
      callback(null, requestOrigin);
    } else {
      callback(new ProviderError(ProviderFailure.Forbidden, null, `Origin ${requestOrigin} not allowed by CORS`));
    }
  }
});