Apply cors before routes
This commit is contained in:
parent
00eadfaf95
commit
b33cc21dad
@ -30,6 +30,7 @@ const FlitterUnits = {
|
||||
* available to the middleware-routing-controller stack.
|
||||
*/
|
||||
'Upload' : new (require('flitter-upload/UploadUnit'))(),
|
||||
'CORS' : new (require('./app/CorsUnit'))(),
|
||||
|
||||
/*
|
||||
* The Core Flitter Units
|
||||
@ -94,4 +95,4 @@ const FlitterUnits = {
|
||||
'App' : new (require('libflitter/app/AppUnit'))(),
|
||||
}
|
||||
|
||||
module.exports = exports = FlitterUnits
|
||||
module.exports = exports = FlitterUnits
|
||||
|
45
app/CorsUnit.js
Normal file
45
app/CorsUnit.js
Normal file
@ -0,0 +1,45 @@
|
||||
const Unit = require('libflitter/Unit')
|
||||
const cors = require('cors')
|
||||
|
||||
/*
|
||||
* The Miscellaneous Unit
|
||||
* -------------------------------------------------------------
|
||||
* This is a Unit file where you should make any modifications that
|
||||
* your application may need such as custom Express add-ons. Changes
|
||||
* here are loaded after the core Flitter units, but before the other
|
||||
* units (secondary, custom, error, and App), so they are available to
|
||||
* other units in the stack.
|
||||
*/
|
||||
class CorsUnit extends Unit {
|
||||
|
||||
/*
|
||||
* Initializes the unit class.
|
||||
* This is called OUTSIDE of a Flitter context,
|
||||
* so no other contexts are available. Modifications here
|
||||
* take place before any part of Flitter is loaded or available.
|
||||
*/
|
||||
constructor(){
|
||||
super()
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the actual Unit.
|
||||
* This is where most of the changes will go.
|
||||
* This is provided an instance of the Express app
|
||||
* so any custom changes can be made. The core Flitter
|
||||
* contexts are available here, so things like config(),
|
||||
* model(), etc. work.
|
||||
*/
|
||||
async go(app, context){
|
||||
app.express.use(cors());
|
||||
}
|
||||
|
||||
name(){
|
||||
return "cors"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = exports = CorsUnit
|
@ -33,8 +33,6 @@ class MiscUnit extends Unit {
|
||||
* model(), etc. work.
|
||||
*/
|
||||
async go(app, context){
|
||||
app.express.use(cors());
|
||||
|
||||
String.prototype.capitalize = function(){
|
||||
return this.charAt(0).toUpperCase() + this.slice(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user