-1

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

Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43
LeeR
  • 1,609
  • 11
  • 29

1 Answers1

0

So, it wasn't even a cors issue. Once I did some more reading it's due to developing on a localhost/127.0.0.1 environment, which is considered to send back "secure" requests, and it was trying to reach the API on unsecure local ip (10.0.0.5). So due to this, Firefox simply blocks all cross origin requests and why it wasn't even making it to my API to log anything out

LeeR
  • 1,609
  • 11
  • 29