Search code examples
node.jsazurenginxstrapiinternal-server-error

Strapi connect endpoint 500 internal server error


I have Strapi installed on Azure VM. trying to connect to the /api/connect/microsoft endpoint to do authorization with active directory. Everything works locally but on the server it keeps giving me a 500 internal server error. Strapi on Azure vm is set up with nginx.

This is what we found in the logs

1|strapi-prod  | [2022-02-18 22:59:00.277] http: GET /api/connect/microsoft (60 ms) 302
1|strapi-prod  |   Error: Cannot send secure cookie over unencrypted connection
1|strapi-prod  |       at Cookies.set (/srv/strapi/strapi/node_modules/cookies/index.js:94:11)
1|strapi-prod  |       at ContextSession.save (/srv/strapi/strapi/node_modules/koa-session/lib/context.js:339:22)
1|strapi-prod  |       at ContextSession.commit (/srv/strapi/strapi/node_modules/koa-session/lib/context.js:239:16)
1|strapi-prod  |       at session (/srv/strapi/strapi/node_modules/koa-session/index.js:46:20)
1|strapi-prod  |       at async /srv/strapi/strapi/node_modules/@strapi/strapi/lib/services/metrics/middleware.js:29:5

Any help is appreciated!


Solution

  • I am not using Stapi but the answer is in the error message:

    Error: Cannot send secure cookie over unencrypted connection

    It means that without using https, in your cookie configuration you should have:

    secure: false

    exemple:

    {
      ...
      httpOnly: true,
      maxAge: 24*60*60*1000,
      secure: false // if true only send cookie over https
      ...
    }