Cross-Origin Resource Sharing is a mechanism that allows resources to be requested from another domain.
npm install @caviajs/http-cors --save
import { HttpCors } from '@caviajs/http-cors';
import { Interceptor } from '@caviajs/http-router';
export const CorsInterceptor: Interceptor = HttpCors.setup(request => {
return {
/*
'Access-Control-Allow-Credentials'?: boolean;
'Access-Control-Allow-Headers'?: string[];
'Access-Control-Allow-Methods'?: ('DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT')[];
'Access-Control-Allow-Origin'?: string;
'Access-Control-Expose-Headers'?: string[];
'Access-Control-Max-Age'?: number;
*/
};
});
import { HttpCors } from '@caviajs/http-cors';
import { Interceptor } from '@caviajs/http-router';
export const CorsInterceptor: Interceptor = HttpCors.setup({
/*
'Access-Control-Allow-Credentials'?: boolean;
'Access-Control-Allow-Headers'?: string[];
'Access-Control-Allow-Methods'?: ('DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT')[];
'Access-Control-Allow-Origin'?: string;
'Access-Control-Expose-Headers'?: string[];
'Access-Control-Max-Age'?: number;
*/
});
httpRouter
.intercept(CorsInterceptor);