Skip to content

Commit

Permalink
Merge pull request #149 from bl4drnnr/web-interface-dev
Browse files Browse the repository at this point in the history
add headers to cors
  • Loading branch information
bl4drnnr authored Apr 6, 2024
2 parents 1d501a1 + fe5407d commit 6166653
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
5 changes: 4 additions & 1 deletion mnemosyne-web-interface/mnemosyne-api-proxy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { urlencoded, json } from 'express';
const whitelist = [
'http://localhost:4200',
'https://mnemosyne.io',
'https://proxy.mnemosyne.io'
'https://proxy.mnemosyne.io',
'http://mnemosyne.io',
'http://proxy.mnemosyne.io'
];

const app = await NestFactory.create(AppModule);
Expand All @@ -21,6 +23,7 @@ import { urlencoded, json } from 'express';
app.use(urlencoded({ extended: true, limit: '50mb' }));

app.enableCors({
allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
credentials: true,
origin: function (origin, callback) {
Expand Down
31 changes: 20 additions & 11 deletions mnemosyne-web-interface/mnemosyne-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { urlencoded, json } from 'express';
const whitelist = [
'http://localhost:4201',
'https://mnemosyne.io',
'https://proxy.mnemosyne.io'
'https://proxy.mnemosyne.io',
'http://mnemosyne.io',
'http://proxy.mnemosyne.io'
];

const app = await NestFactory.create(AppModule);
Expand All @@ -20,18 +22,25 @@ import { urlencoded, json } from 'express';
app.use(json({ limit: '50mb' }));
app.use(urlencoded({ extended: true, limit: '50mb' }));

// app.enableCors({
// methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
// credentials: true,
// origin: function (origin, callback) {
// if (whitelist.indexOf(origin) !== -1) {
// console.log('allowed cors for (API):', origin);
// callback(null, true);
// } else {
// console.log('blocked cors for:', origin);
// callback(new Error('Not allowed by CORS (API)'));
// }
// }
// });

app.enableCors({
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
credentials: true,
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
console.log('allowed cors for (API):', origin);
callback(null, true);
} else {
console.log('blocked cors for:', origin);
callback(new Error('Not allowed by CORS (API)'));
}
}
allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
origin: whitelist,
credentials: true
});

// app.enableCors({
Expand Down

0 comments on commit 6166653

Please sign in to comment.