Skip to content

Commit

Permalink
[REFACTORING]: moved CorsOptions to core-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Olga Yasnopolskaya committed Jan 28, 2025
1 parent 8d79231 commit 68f1fd8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 48 deletions.
14 changes: 2 additions & 12 deletions v6y-apps/bfb-devops-auditor/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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());
Expand Down
14 changes: 2 additions & 12 deletions v6y-apps/bfb-dynamic-auditor/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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());
Expand Down
14 changes: 2 additions & 12 deletions v6y-apps/bfb-main-analyzer/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 2 additions & 12 deletions v6y-apps/bfb-static-auditor/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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());
Expand Down
11 changes: 11 additions & 0 deletions v6y-libs/core-logic/src/config/CorsOptions.ts
Original file line number Diff line number Diff line change
@@ -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);
},
};
1 change: 1 addition & 0 deletions v6y-libs/core-logic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 68f1fd8

Please sign in to comment.