Skip to content

Commit

Permalink
Merge pull request #86 from NovaDrake76/dev
Browse files Browse the repository at this point in the history
fix: disabled cors on dev env
  • Loading branch information
NovaDrake76 authored Jun 11, 2024
2 parents 7475c71 + fc44128 commit 5504473
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@ require("dotenv").config();
const app = express();
const server = http.createServer(app);

const isDevelopment = process.env.NODE_ENV === 'development';

const corsOptions = {
origin: 'https://kanicasino.com',
origin: isDevelopment ? '*' : 'https://kanicasino.com',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
credentials: true,
};

app.use(cors(corsOptions));

app.use((req, res, next) => {
const allowedOrigins = ['https://kanicasino.com'];
const allowedOrigins = isDevelopment ? ['*'] : ['https://kanicasino.com'];
const origin = req.headers.origin;

if (allowedOrigins.includes(origin)) {
if (allowedOrigins.includes('*') || allowedOrigins.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
}

next();
});

const io = socketIO(server, {
cors: {
origin: 'https://kanicasino.com',
methods: ['GET', 'POST'],
origin: isDevelopment ? '*' : 'https://kanicasino.com',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
credentials: true,
},
});
Expand Down

0 comments on commit 5504473

Please sign in to comment.