Skip to content

Commit

Permalink
default is handled in core now
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws committed Oct 23, 2023
1 parent 060dba7 commit 1d93ef0
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/resources/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,6 @@ interface ApiDetails {
url: string;
}

const defaultCorsOptions: CorsOptions = {
allowOrigins: ['*'],
allowHeaders: ['Content-Type', 'Authorization'],
allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowCredentials: false,
exposeHeaders: [],
maxAge: '300 seconds',
};

/**
* API Resource
*
Expand Down Expand Up @@ -423,11 +414,6 @@ export class Api<SecurityDefs extends string> extends Base<ApiDetails> {
middleware: [...this.middleware, ...routeMiddleware],
});

if (this.cors && !this.routes.some((rr) => rr.path === r.path)) {
// register options handler
r.options([]);
}

this.routes.push(r);

return r;
Expand Down Expand Up @@ -604,18 +590,17 @@ export class Api<SecurityDefs extends string> extends Base<ApiDetails> {
}

if (cors) {
const corsConfig = {
...defaultCorsOptions,
...(typeof cors === 'object' ? cors : undefined),
};
const corsConfig = typeof cors === 'object' ? cors : {};
const corsDef = new ApiCorsDefinition();

corsDef.setAllowcredentials(corsConfig.allowCredentials);
corsDef.setAlloworiginsList(corsConfig.allowOrigins);
corsDef.setAllowheadersList(corsConfig.allowHeaders);
corsDef.setAllowmethodsList(corsConfig.allowMethods);
corsDef.setExposeheadersList(corsConfig.exposeHeaders);
corsDef.setMaxage(durationToSeconds(corsConfig.maxAge));
corsDef.setMaxage(
corsConfig.maxAge ? durationToSeconds(corsConfig.maxAge) : undefined
);

apiResource.setCors(corsDef);
}
Expand Down

0 comments on commit 1d93ef0

Please sign in to comment.