americano
americano copied to clipboard
Changing the way configuration is defined
Can we change the way configuration is defined? I don't like it because I find it hard to read and to write, therefore error-prone. I'm in favor of a raw-express like config definition:
path = require 'path'
americano = require 'americano'
bodyParser = require 'body-parser'
methodOverride = require 'method-override'
errorHandler = require 'errorhandler'
morgan = require 'morgan'
config =
common:
use: [
bodyParser()
methodOverride()
errorHandler()
americano.static path.resolve(__dirname, '../client/public'),
maxAge: 86400000
]
set:
views: path.resolve __dirname, '../client'
development: [
morgan 'dev'
]
production: [
morgan 'short'
]
plugins: [
'americano-cozy'
]
module.exports = config
Could be changed to:
path = require 'path'
americano = require 'americano'
bodyParser = require 'body-parser'
methodOverride = require 'method-override'
errorHandler = require 'errorhandler'
morgan = require 'morgan'
config =
common: (app) ->
app.use bodyParser()
app.use methodOverride()
app.use errorHandler()
app.use americano.static path.resolve(__dirname, '../client/public'),
maxAge: 86400000
app.set 'views', path.resolve __dirname, '../client'
development: (app) ->
app.use morgan 'dev'
production: (app) ->
app.use morgan 'short'
plugins: [
'americano-cozy'
]
module.exports = config
While I agree there is redundant code to write, I feel more comfortable with it. That may just be my personal un-argumented opinion though.
Americano brings a framework to the Express project. It avoids repetition and brings a frame to your project. Your example is not complete because it doesn't show the case where people don't write proper code. Here is another example of where it could lead:
config =
common: (app) ->
app.use bodyParser()
app.set 'views', path.resolve __dirname, '../client'
app.use methodOverride()
app.set 'coolsettings', 'settings'
app.use errorHandler()
app.use americano.static path.resolve(__dirname, '../client/public'),
maxAge: 86400000
development: (app) ->
app.use morgan 'dev'
production: (app) ->
app.use morgan 'short'
plugins: [
'americano-cozy'
]
For both reasons (repetition and lack of frame), I think we should keep the current configuration.