-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: organize between middlewares and routes
It will make the app.js file much more simple to read and every little execution is moved to a module that can easily be tested.
Mateu Aguiló Bosch
committed
May 28, 2018
1 parent
2e0a100
commit 2c5e925
Showing
12 changed files
with
63 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @flow | ||
|
||
import type { ObjectLiteral } from '../../flow/types/common'; | ||
|
||
/** | ||
* Returns a middleware that will copy all of the properties to the request. | ||
* | ||
* This is useful to store variables that will be used in any arbitrary | ||
* middleware down the process. | ||
*/ | ||
module.exports = (args: ObjectLiteral) => ( | ||
req: any, | ||
res: any, | ||
next: Function | ||
): void => { | ||
Object.keys(args).forEach(key => { | ||
req[key] = args[key]; | ||
}); | ||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @flow | ||
|
||
const config = require('config'); | ||
|
||
/** | ||
* A custom implementation of CORS. | ||
*/ | ||
module.exports = (req: any, res: any, next: Function): void => { | ||
// Enable CORS. | ||
res.set('Access-Control-Allow-Origin', '*'); | ||
res.set( | ||
'Access-Control-Allow-Headers', | ||
config.get('cors.headers').join(', ') | ||
); | ||
next(); | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @flow | ||
|
||
/** | ||
* A healthcheck endpoint. | ||
* | ||
* Useful for auto-scaling policies, like EC2. | ||
*/ | ||
module.exports = (req: any, res: any): void => { | ||
res.set('Cache-Control', 'private, max-age=0, no-cache'); | ||
res.json({ meta: { healthcheck: 'good' } }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters