Categories
Development

Adonis.js, Ionic and Cors

I’m trying to get CORS working on my adonis.js backend, and ionic front end but I can’t get anything working for some reason.

I’ve added the cors provider to my app.js

const providers = [
    '@adonisjs/framework/providers/AppProvider',
    '@adonisjs/auth/providers/AuthProvider',
    '@adonisjs/bodyparser/providers/BodyParserProvider',
    '@adonisjs/lucid/providers/LucidProvider',
    '@adonisjs/cors/providers/CorsProvider',
];

loaded it in kernel.js

const serverMiddleware = [
    'Adonis/Middleware/Cors',
];

Server
    .registerGlobal(globalMiddleware)
    .registerNamed(namedMiddleware)
    .use(serverMiddleware);

and I’ve set my origin: true and no matter what I do, nothing seems to be fixing it. I’ve even done the following function with origin to try get it to log out the origin, and nothing is being logged out, so it makes me wonder if it’s even loading my cors.js config.

origin: function (currentOrigin) {
    Logger.info(currentOrigin);
    return currentOrigin === 'mywebsite.com'
},

Does anyone have any idea as to how to get it working? Many thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *