Refactor CLI and add tests

This commit is contained in:
Typicode
2015-07-15 18:44:33 +02:00
parent e3a7db949b
commit ccf67724e3
22 changed files with 368 additions and 172 deletions

41
src/server/defaults.js Normal file
View File

@ -0,0 +1,41 @@
var fs = require('fs')
var express = require('express')
var logger = require('morgan')
var cors = require('cors')
var errorhandler = require('errorhandler')
var arr = []
// Logger
arr.push(logger('dev', {
skip: function (req, res) {
return process.env.NODE_ENV === 'test' ||
req.path === '/favicon.ico'
}
}))
// Enable CORS for all the requests, including static files
arr.push(cors({ origin: true, credentials: true }))
if (process.env.NODE_ENV === 'development') {
// only use in development
arr.push(errorhandler())
}
// Serve static files
if (fs.existsSync(process.cwd() + '/public')) {
arr.push(express.static(process.cwd() + '/public'))
} else {
arr.push(express.static(__dirname + '/public'))
}
// No cache for IE
// https://support.microsoft.com/en-us/kb/234067
arr.push(function (req, res, next) {
res.header('Cache-Control', 'no-cache')
res.header('Pragma', 'no-cache')
res.header('Expires', '-1')
next()
})
module.exports = arr