mirror of
https://github.com/typicode/json-server.git
synced 2025-07-31 06:01:50 +08:00
moving logger after express.static to prevent unnecessary logging of static files with express (#587)
This commit is contained in:
@ -22,16 +22,6 @@ module.exports = function(opts) {
|
|||||||
arr.push(compression())
|
arr.push(compression())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logger
|
|
||||||
if (opts.logger) {
|
|
||||||
arr.push(
|
|
||||||
logger('dev', {
|
|
||||||
skip: req =>
|
|
||||||
process.env.NODE_ENV === 'test' || req.path === '/favicon.ico'
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable CORS for all the requests, including static files
|
// Enable CORS for all the requests, including static files
|
||||||
if (!opts.noCors) {
|
if (!opts.noCors) {
|
||||||
arr.push(cors({ origin: true, credentials: true }))
|
arr.push(cors({ origin: true, credentials: true }))
|
||||||
@ -45,6 +35,16 @@ module.exports = function(opts) {
|
|||||||
// Serve static files
|
// Serve static files
|
||||||
arr.push(express.static(opts.static))
|
arr.push(express.static(opts.static))
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
if (opts.logger) {
|
||||||
|
arr.push(
|
||||||
|
logger('dev', {
|
||||||
|
skip: req =>
|
||||||
|
process.env.NODE_ENV === 'test' || req.path === '/favicon.ico'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// No cache for IE
|
// No cache for IE
|
||||||
// https://support.microsoft.com/en-us/kb/234067
|
// https://support.microsoft.com/en-us/kb/234067
|
||||||
arr.push((req, res, next) => {
|
arr.push((req, res, next) => {
|
||||||
|
Reference in New Issue
Block a user