Skip to content

Commit

Permalink
Trim origins
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikthepixel committed Jan 10, 2024
1 parent 0792ef0 commit d579db6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions apps/gateway/src/middleware/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ export interface CorsOptions extends Omit<MakeCorsOptions, 'origin'> {

const cors = ({ origin, ...opts }: CorsOptions = {}) => {
const whitelistedOrigins = Array.isArray(origin)
? (origin.filter((org) => Boolean(org)) as string[])
? (origin.filter((org) => Boolean(org)) as string[]).map((org) => org.trim())
: typeof origin === 'string'
? [origin]
? [origin.trim()]
: undefined;

return makeCors({
origin(reqOrigin, callback) {
const verdict =
whitelistedOrigins &&
reqOrigin &&
whitelistedOrigins.includes(reqOrigin);
whitelistedOrigins.includes(reqOrigin.trim());

callback(null, verdict);
},
Expand Down

0 comments on commit d579db6

Please sign in to comment.