Skip to content

Commit

Permalink
Merge pull request #130 from bl4drnnr/web-interface-dev
Browse files Browse the repository at this point in the history
cors for the api v
  • Loading branch information
bl4drnnr authored Mar 3, 2024
2 parents 1eaa990 + e23a22d commit 8587890
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
45 changes: 21 additions & 24 deletions mnemosyne-web-interface/mnemosyne-api-proxy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,33 @@ import * as bodyParser from 'body-parser';

app.setGlobalPrefix('/api');

const whitelist = [
'http://localhost:4200',
'https://mnemosyne.io',
'http://mnemosyne.io',
'http://api.mnemosyne.io',
'https://api.mnemosyne.io'
];
// const whitelist = [
// 'http://localhost:4200',
// 'https://mnemosyne.io',
// 'http://mnemosyne.io',
// 'http://api.mnemosyne.io',
// 'https://api.mnemosyne.io'
// ];
//
// app.enableCors({
// origin: function (origin, callback) {
// if (whitelist.indexOf(origin) !== -1) {
// console.log("allowed cors for:", origin)
// callback(null, true)
// } else {
// console.log("blocked cors for:", origin)
// callback(new Error('Not allowed by CORS'))
// }
// }
// });

app.enableCors({
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
console.log("allowed cors for:", origin)
callback(null, true)
} else {
console.log("blocked cors for:", origin)
callback(new Error('Not allowed by CORS'))
}
console.log("allowed cors for proxy api:", origin)
callback(null, true)
}
});

// app.enableCors({
// origin: [
// 'http://localhost:4200',
// 'https://mnemosyne.io',
// 'http://mnemosyne.io',
// 'http://api.mnemosyne.io',
// 'https://api.mnemosyne.io'
// ],
// });

const config = new DocumentBuilder()
.setTitle('Mnemosyne')
.setDescription('Documentation of Mnemosyne Proxy API.')
Expand Down
17 changes: 2 additions & 15 deletions mnemosyne-web-interface/mnemosyne-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,10 @@ import * as yaml from 'yaml';

app.setGlobalPrefix('/api');

const whitelist = [
'http://localhost:4200',
'https://mnemosyne.io',
'http://mnemosyne.io',
'http://proxy.mnemosyne.io',
'https://proxy.mnemosyne.io'
];

app.enableCors({
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
console.log("allowed cors for:", origin)
callback(null, true)
} else {
console.log("blocked cors for:", origin)
callback(new Error('Not allowed by CORS'))
}
console.log("allowed cors for api:", origin)
callback(null, true)
}
});

Expand Down

0 comments on commit 8587890

Please sign in to comment.