Initial commit of framework
This commit is contained in:
32
app/routing/middleware/HomeLogger.middleware.js
Normal file
32
app/routing/middleware/HomeLogger.middleware.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const { Middleware } = require('libflitter')
|
||||
|
||||
/*
|
||||
* HomeLogger Middleware
|
||||
* -------------------------------------------------------------
|
||||
* This is a sample middleware. It simply prints a console message when
|
||||
* the route that it is tied to is accessed. By default, it is called if
|
||||
* the '/' route is accessed. It can be injected in routes globally using
|
||||
* the middlewares service.
|
||||
*/
|
||||
class HomeLogger extends Middleware {
|
||||
static get services() {
|
||||
return [...super.services, 'output']
|
||||
}
|
||||
|
||||
/*
|
||||
* Run the middleware test.
|
||||
* This method is required by all Flitter middleware.
|
||||
* It should either call the next function in the stack,
|
||||
* or it should handle the response accordingly.
|
||||
*/
|
||||
test(req, res, next, args) {
|
||||
this.output.debug('Home was accessed!')
|
||||
|
||||
/*
|
||||
* Call the next function in the stack.
|
||||
*/
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HomeLogger
|
||||
7
app/routing/middleware/i18n/Localize.middleware.js
Normal file
7
app/routing/middleware/i18n/Localize.middleware.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const Middleware = require('flitter-i18n/src/middleware/Localize')
|
||||
|
||||
class LocalizeMiddleware extends Middleware {
|
||||
|
||||
}
|
||||
|
||||
module.exports = exports = LocalizeMiddleware
|
||||
7
app/routing/middleware/i18n/Scope.middleware.js
Normal file
7
app/routing/middleware/i18n/Scope.middleware.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const Middleware = require('flitter-i18n/src/middleware/Scope')
|
||||
|
||||
class ScopeMiddleware extends Middleware {
|
||||
|
||||
}
|
||||
|
||||
module.exports = exports = ScopeMiddleware
|
||||
43
app/routing/middleware/util/Config.middleware.js
Normal file
43
app/routing/middleware/util/Config.middleware.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const { Middleware } = require('libflitter')
|
||||
|
||||
/*
|
||||
* Config Middleware
|
||||
* -------------------------------------------------------------
|
||||
* Checks the specified configuration key (and optionally the value).
|
||||
* If the configuration matches the required value, the request can
|
||||
* proceed. Otherwise, a 404 will be returned.
|
||||
*
|
||||
* To use, add the call to your route's middleware:
|
||||
*
|
||||
* ['middleware::util:Config', {key: 'server.ssl.test', value: true}],
|
||||
*
|
||||
* In this case, the request would be allowed to proceed in the case:
|
||||
* services.configs.get('server.ssl.test') === true
|
||||
*
|
||||
* The 'value' attribute is optional. If none is provided, the request
|
||||
* can proceed if the config value is truthy.
|
||||
*/
|
||||
class Config extends Middleware {
|
||||
static get services() {
|
||||
return [...super.services, 'configs', 'output']
|
||||
}
|
||||
|
||||
/*
|
||||
* Run the middleware test.
|
||||
*/
|
||||
test(req, res, next, args = {}){
|
||||
if ( !args.key ) return res.error(500)
|
||||
|
||||
const config = this.configs.get(args.key)
|
||||
|
||||
if ( !args.value && !config ) {
|
||||
if ( !config && typeof config === 'undefined' )
|
||||
this.output.warn(`util:Config middleware check failed because it tried to access a config that doesn't exist. (${key})`)
|
||||
return res.error(404)
|
||||
}
|
||||
else if ( args.value && args.value !== config ) return res.error(404)
|
||||
else return next()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Config
|
||||
Reference in New Issue
Block a user