5xx stacktrace and CORS config ctx

articles/error_500.jpg

5xx error stacktrace

Since @adonisjs/[email protected] errors with error codes 500 and above will get their stacktrace logged thro @adonisjs/logger

With 5xx errors you can now just check server logs to see whole stacktrace of error, not just error message itself. Makes debugging errors quite a lot easier and more convenient

Request context in CORS config

CORS config options that also accepted methods as their configuration options (enabled, origin and headers) now get request context as second input parameter

This allows to set CORS options per request based on signed in user, request payload, cookies and everything else related to HttpContextContract

For example different CORS options based on user role

import { CorsConfig } from '@ioc:Adonis/Core/Cors'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

const ALLOWED_ORIGINS = ['example.com', 'foobar.dev']

const corsConfig: CorsConfig = {
  origin: (requestOrigin: string, ctx: HttpContextContract) => {
    // Allow all origins for admins
    if (ctx.auth.user.role === 'ADMIN') {
      return true
    }
    // Allow only certain origins for regular users
    return ALLOWED_ORIGINS.includes(requestOrigin)
  }
}
The Latest