Skip to content

Commit

Permalink
Merge pull request #151 from bl4drnnr/web-interface-dev
Browse files Browse the repository at this point in the history
update allowed headers and cloudflare dns
  • Loading branch information
bl4drnnr authored Apr 6, 2024
2 parents 26c2770 + 7d6c016 commit 92f7294
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 44 deletions.
51 changes: 29 additions & 22 deletions mnemosyne-web-interface/mnemosyne-api-proxy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,42 @@ import { urlencoded, json } from 'express';
// }
// });

app.use(cors({
allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
const message = `allowed cors for (API Proxy): ${origin}\n`;
fs.appendFile('cors_logs.txt', message, (err) => {
if (err) throw err;
console.log('Cors log appended to file');
});
callback(null, true);
} else {
const message = `blocked cors for (API Proxy): ${origin}\n`;
fs.appendFile('cors_logs.txt', message, (err) => {
if (err) throw err;
console.log('Cors log appended to file');
});
callback(new Error('Not allowed by CORS'));
}
},
credentials: true,
}));
// app.use(cors({
// allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
// methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
// origin: function (origin, callback) {
// if (whitelist.indexOf(origin) !== -1) {
// const message = `allowed cors for (API Proxy): ${origin}\n`;
// fs.appendFile('cors_logs.txt', message, (err) => {
// if (err) throw err;
// console.log('Cors log appended to file');
// });
// callback(null, true);
// } else {
// const message = `blocked cors for (API Proxy): ${origin}\n`;
// fs.appendFile('cors_logs.txt', message, (err) => {
// if (err) throw err;
// console.log('Cors log appended to file');
// });
// callback(new Error('Not allowed by CORS'));
// }
// },
// credentials: true,
// }));

// app.enableCors({
// allowedHeaders: ['content-type'],
// origin: 'https://mnemosyne.io',
// credentials: true
// });

app.enableCors({
allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
origin: whitelist,
credentials: true
});

// Working in the development mode
// app.enableCors({
// origin: ['http://localhost:4200', 'https://mnemosyne.io'],
Expand Down
51 changes: 29 additions & 22 deletions mnemosyne-web-interface/mnemosyne-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,41 @@ import { urlencoded, json } from 'express';
// }
// });

app.use(cors({
allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
const message = `allowed cors for (API): ${origin}\n`;
fs.appendFile('cors_logs.txt', message, (err) => {
if (err) throw err;
console.log('Cors log appended to file');
});
callback(null, true);
} else {
const message = `blocked cors for (API): ${origin}\n`;
fs.appendFile('cors_logs.txt', message, (err) => {
if (err) throw err;
console.log('Cors log appended to file');
});
callback(new Error('Not allowed by CORS'));
}
},
credentials: true,
}));
// app.use(cors({
// allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
// methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
// origin: function (origin, callback) {
// if (whitelist.indexOf(origin) !== -1) {
// const message = `allowed cors for (API): ${origin}\n`;
// fs.appendFile('cors_logs.txt', message, (err) => {
// if (err) throw err;
// console.log('Cors log appended to file');
// });
// callback(null, true);
// } else {
// const message = `blocked cors for (API): ${origin}\n`;
// fs.appendFile('cors_logs.txt', message, (err) => {
// if (err) throw err;
// console.log('Cors log appended to file');
// });
// callback(new Error('Not allowed by CORS'));
// }
// },
// credentials: true,
// }));

// app.enableCors({
// origin: 'https://proxy.mnemosyne.io',
// credentials: true
// });

app.enableCors({
allowedHeaders: ['Content-Type', 'Authorization', 'X-Access-Token'],
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
origin: whitelist,
credentials: true
});

// Working in the development mode
// app.enableCors({
// origin: ['http://localhost:4201', 'https://proxy.mnemosyne.io'],
Expand Down

0 comments on commit 92f7294

Please sign in to comment.