Skip to content

KCORS Setup #435

Closed
Closed
@daveabes

Description

@daveabes

Has the cors configuration for routing controllers using koa changed?

Using the method found on the github page, I'm no successfully enabling cors and am quite unsure if the method to setup cors has changed.

Is the following still the correct way to setup cors for KOA and Routing Controllers?

 this.app = await createKoaServer({
            cors: this.getCorsConfiguration(),
            controllers: [
                IndexController
            ],
            routePrefix: process.env.HTTP_BASEPATH,
            classTransformer: true
        });

Here is the configuration:

 return {
            origin: (ctx: koa.Context) => {
                this.dlogger.log(`[NODE] Verifying cors`);
                const whitelist: string[] = this.getCorsOriginWhitelist();
                const requestOrigin = ctx.request.headers.origin;
                if (!(whitelist.indexOf(requestOrigin) > -1)) {
                    return requestOrigin;
                }
                return false;
            },
            allowMethods: this.getCorsAllowedMethods(),
            allowHeaders: this.getCorsAllowedHeaders(),
            maxAge: 60
        };

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: awaiting answerAwaiting answer from the author of issue or PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions