Skip to content

Commit

Permalink
Merge pull request #26 from XinFinOrg/add-cors-config
Browse files Browse the repository at this point in the history
add cors config
  • Loading branch information
wanwiset25 authored Aug 3, 2023
2 parents 288dcd7 + 60b5aaf commit c7ad2d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import hpp from 'hpp';
import morgan from 'morgan';
import swaggerJSDoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import { LOG_FORMAT } from './config';
import cors from 'cors';
import { LOG_FORMAT, CORS_ALLOW_ORIGIN } from './config';
import { Routes } from './interfaces/routes.interface';
import { ErrorMiddleware } from './middlewares/error.middleware';
import { logger, stream } from './utils/logger';


export class App {
public app: express.Application;

Expand All @@ -36,6 +38,9 @@ export class App {
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: true }));
this.app.use(cookieParser());
if (CORS_ALLOW_ORIGIN != ''){
this.app.use(cors({origin: CORS_ALLOW_ORIGIN}));
}
}

private initializeRoutes(routes: Routes[]) {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ if (!PARENTCHAIN_WALLET || !CHECKPOINT_CONTRACT) {
}

export const { NODE_ENV, LOG_FORMAT, STATS_SECRET } = process.env;

export const CORS_ALLOW_ORIGIN = process.env || '';

0 comments on commit c7ad2d4

Please sign in to comment.