diff --git a/v6y-apps/bfb-devops-auditor/src/index.ts b/v6y-apps/bfb-devops-auditor/src/index.ts index 1a247ce..cda638b 100644 --- a/v6y-apps/bfb-devops-auditor/src/index.ts +++ b/v6y-apps/bfb-devops-auditor/src/index.ts @@ -1,4 +1,4 @@ -import { AppLogger, ServerUtils } from '@v6y/core-logic'; +import { AppLogger, CorsOptions, ServerUtils } from '@v6y/core-logic'; import bodyParser from 'body-parser'; import cookieParser from 'cookie-parser'; import cors from 'cors'; @@ -34,17 +34,7 @@ const httpServer = createServer({ app.use(cookieParser()); // CORS (Cross-Origin Resource Sharing): Configures the server to allow requests from other origins. -const corsOptions = { - origin: function ( - origin: string | undefined, - callback: (err: Error | null, origin?: string) => void, - ) { - AppLogger.debug(`CORS origin redirect: ${origin}`); - callback(null, origin); - }, -}; - -app.use(cors(corsOptions)); +app.use(cors(CorsOptions)); // Body Parser: Parses incoming request bodies in different formats (URL-encoded, JSON). app.use(bodyParser.json()); diff --git a/v6y-apps/bfb-dynamic-auditor/src/index.ts b/v6y-apps/bfb-dynamic-auditor/src/index.ts index fe60bdc..01405f8 100644 --- a/v6y-apps/bfb-dynamic-auditor/src/index.ts +++ b/v6y-apps/bfb-dynamic-auditor/src/index.ts @@ -1,4 +1,4 @@ -import { AppLogger, ServerUtils } from '@v6y/core-logic'; +import { AppLogger, CorsOptions, ServerUtils } from '@v6y/core-logic'; import bodyParser from 'body-parser'; import cookieParser from 'cookie-parser'; import cors from 'cors'; @@ -35,17 +35,7 @@ const httpServer = createServer({ app.use(cookieParser()); // CORS (Cross-Origin Resource Sharing): Configures the server to allow requests from other origins. -const corsOptions = { - origin: function ( - origin: string | undefined, - callback: (err: Error | null, origin?: string) => void, - ) { - AppLogger.debug(`CORS origin redirect: ${origin}`); - callback(null, origin); - }, -}; - -app.use(cors(corsOptions)); +app.use(cors(CorsOptions)); // Body Parser: Parses incoming request bodies in different formats (URL-encoded, JSON). app.use(bodyParser.json()); diff --git a/v6y-apps/bfb-main-analyzer/src/index.ts b/v6y-apps/bfb-main-analyzer/src/index.ts index 49656d4..899af2f 100644 --- a/v6y-apps/bfb-main-analyzer/src/index.ts +++ b/v6y-apps/bfb-main-analyzer/src/index.ts @@ -1,4 +1,4 @@ -import { AppLogger, ServerUtils } from '@v6y/core-logic'; +import { AppLogger, CorsOptions, ServerUtils } from '@v6y/core-logic'; import BodyParser from 'body-parser'; import CookieParser from 'cookie-parser'; import Cors from 'cors'; @@ -28,17 +28,7 @@ app.use(CookieParser()); // configure cors // https://expressjs.com/en/resources/middleware/cors.html -const corsOptions = { - origin: function ( - origin: string | undefined, - callback: (err: Error | null, origin?: string) => void, - ) { - AppLogger.debug('Redirection cors orgin : ' + origin); - callback(null, origin); - }, -}; - -app.use(Cors(corsOptions)); +app.use(Cors(CorsOptions)); // parse application/x-www-form-urlencoded app.use( diff --git a/v6y-apps/bfb-static-auditor/src/index.ts b/v6y-apps/bfb-static-auditor/src/index.ts index 27bc883..ca4b037 100644 --- a/v6y-apps/bfb-static-auditor/src/index.ts +++ b/v6y-apps/bfb-static-auditor/src/index.ts @@ -1,4 +1,4 @@ -import { AppLogger, ServerUtils } from '@v6y/core-logic'; +import { AppLogger, CorsOptions, ServerUtils } from '@v6y/core-logic'; import bodyParser from 'body-parser'; import cookieParser from 'cookie-parser'; import cors from 'cors'; @@ -35,17 +35,7 @@ const httpServer = createServer({ app.use(cookieParser()); // CORS (Cross-Origin Resource Sharing): Configures the server to allow requests from other origins. -const corsOptions = { - origin: function ( - origin: string | undefined, - callback: (err: Error | null, origin?: string) => void, - ) { - AppLogger.debug(`CORS origin redirect: ${origin}`); - callback(null, origin); - }, -}; - -app.use(cors(corsOptions)); +app.use(cors(CorsOptions)); // Body Parser: Parses incoming request bodies in different formats (URL-encoded, JSON). app.use(bodyParser.json()); diff --git a/v6y-libs/core-logic/src/config/CorsOptions.ts b/v6y-libs/core-logic/src/config/CorsOptions.ts new file mode 100644 index 0000000..2e9fce2 --- /dev/null +++ b/v6y-libs/core-logic/src/config/CorsOptions.ts @@ -0,0 +1,11 @@ +import AppLogger from '../core/AppLogger.ts'; + +export const CorsOptions = { + origin: function ( + origin: string | undefined, + callback: (err: Error | null, origin?: string) => void, + ) { + AppLogger.debug(`CORS origin redirect: ${origin}`); + callback(null, origin); + }, +}; diff --git a/v6y-libs/core-logic/src/index.ts b/v6y-libs/core-logic/src/index.ts index dc3f3b2..265813c 100644 --- a/v6y-libs/core-logic/src/index.ts +++ b/v6y-libs/core-logic/src/index.ts @@ -28,6 +28,7 @@ export * from './config/CodeSmellConfig.ts'; export * from './config/DependencyStatusHelpConfig.ts'; export * from './config/getServerConfig.ts'; export * from './config/getEnvironmentContext.ts'; +export * from './config/CorsOptions.ts'; export * from './core/AuthenticationHelper.ts';