Skip to content

Commit

Permalink
ran: formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzNotABug committed Oct 4, 2024
1 parent 5ecb183 commit 746519a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions middlewares/cors/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const configOptions = {
*
* TODO: Remove this jsdoc comment once the linked PR goes through!
*/
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE']
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
};

/**
Expand All @@ -28,14 +28,13 @@ const configOptions = {
* @param {string[]} [options.methods=['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE']] - Specifies the
* methods allowed when accessing the resource. This is reflected in the 'Access-Control-Allow-Methods' header.
*/
export default function(options = {}) {

export default function (options = {}) {
const {
origin = '*',
excludes = [],
preFlightContinue = false,
optionsSuccessStatus = 204,
methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE']
methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
} = options;

configOptions.origin = origin;
Expand All @@ -53,11 +52,10 @@ export default function(options = {}) {
} catch (err) {
error(`Error applying CORS policy: ${err.message}`);
}
}
},
};
}


/**
* Check if a path is excluded for cors.
*
Expand All @@ -69,7 +67,7 @@ const isPathExcluded = (request) => {
return excludes.some((exclude) =>
typeof exclude === 'string'
? exclude === request.path
: exclude.test(request.path)
: exclude.test(request.path),
);
};

Expand All @@ -83,7 +81,7 @@ function applyCorsHeaders(request, response) {
const headers = {
...configureOrigin(request),
...configureMethods(),
...configureAllowedHeaders(request)
...configureAllowedHeaders(request),
};

// noinspection JSUnresolvedReference
Expand Down Expand Up @@ -154,7 +152,7 @@ function configureOrigin(request) {
*/
function configureMethods() {
return {
'Access-Control-Allow-Methods': configOptions.methods.join(',')
'Access-Control-Allow-Methods': configOptions.methods.join(','),
};
}

Expand Down

0 comments on commit 746519a

Please sign in to comment.