routing-controllers icon indicating copy to clipboard operation
routing-controllers copied to clipboard

KCORS Setup

Open daveabes opened this issue 8 years ago • 3 comments

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
        };

daveabes avatar Sep 03 '18 05:09 daveabes

The reason I'm asking is because the kcors npm package reports using it using another configuration technique:

npm install @koa/cors@2 --save

and then app.use(cors({confg}))

daveabes avatar Sep 03 '18 05:09 daveabes

Stale issue message

github-actions[bot] avatar Feb 08 '20 00:02 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 12 '20 00:12 github-actions[bot]