Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into jb/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
revolunet authored Jan 24, 2024
2 parents 806b281 + d48c07c commit 0779798
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const userStatusOptions = [

const memberTypeOptions = [
{ name: `Membre d'une startup ou d'un incubateur`, key: MemberType.BETA },
{ name: 'Attributaire', key: MemberType.ATTRIBUTAIRE },
{
name: 'Responsable de compte chez un attributaire',
key: MemberType.ATTRIBUTAIRE,
},
{
name: `Membre d'un autre service DINUM (etalab, ...)`,
key: MemberType.DINUM,
Expand Down
17 changes: 12 additions & 5 deletions src/utils/corsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ var whitelist = config.CORS_ORIGIN;

const corsOptions = {
origin: function (origin, callback) {
if (
whitelist.indexOf(origin) !== -1 ||
process.env.NODE_ENV === 'test' ||
!origin
) {
const isAllowed = whitelist.some((allowedOrigin) => {
// Check if the whitelist entry is a string representation of a regex
if (allowedOrigin.startsWith('/') && allowedOrigin.endsWith('/')) {
const pattern = allowedOrigin.slice(1, -1); // Remove the slashes
const regex = new RegExp(pattern);
return regex.test(origin);
}
// Handle normal string comparison
return origin === allowedOrigin;
});

if (isAllowed || process.env.NODE_ENV === 'test' || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
Expand Down

0 comments on commit 0779798

Please sign in to comment.