Skip to content
Permalink
Browse files

refactor: add cors middleware to the container

  • Loading branch information...
thetutlage committed Jun 2, 2019
1 parent c661fc5 commit c15f775a00a894912df3b4130f839e36ff8f0bc5
Showing with 12 additions and 0 deletions.
  1. +12 −0 providers/AppProvider.ts
@@ -17,6 +17,7 @@ import { requireAll } from '@poppinss/utils'
import { ApplicationContract } from '@poppinss/application'
import { Emitter } from '@poppinss/events'
import { Server, HttpContext, MiddlewareStore, Router, routePreProcessor } from '@poppinss/http-server'
import { Cors } from '../src/Cors'

import { HttpExceptionHandler } from '../src/HttpExceptionHandler'
import { envLoader } from '../src/envLoader'
@@ -126,6 +127,16 @@ export default class AppProvider {
})
}

/**
* Registers `cors` middleware to the container
*/
protected $registerCorsMiddleware () {
this.$container.bind('Adonis/Core/CorsMiddleware', () => {
const Config = this.$container.use('Adonis/Core/Config')
return new Cors(Config.get('cors', {}))
})
}

/**
* Registering all required bindings to the container
*/
@@ -139,5 +150,6 @@ export default class AppProvider {
this.$registerHttpServer()
this.$registerHttpExceptionHandler()
this.$registerEmitter()
this.$registerCorsMiddleware()
}
}

0 comments on commit c15f775

Please sign in to comment.
You can’t perform that action at this time.