all files / middleware/ favicon.js

100% Statements 13/13
100% Branches 2/2
100% Functions 1/1
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                     
/**
 * serve favicon requests
 **/
'use strict';
 
const $       = require('lodash');
const debug   = require('debug')('lark.middlewares.favicon');
const assert  = require('assert');
const favicon = require('koa-favicon');
const path    = require('path');
const utils   = require('lark-utils');
 
debug('loading ...');
 
function middleware (config = {}) {
    const pathname = utils.path.absolute(config.path || 'static/favicon.ico');
    assert(path.isAbsolute(pathname), 'Invalid favicon resource path');
    return favicon(pathname, $.cloneDeep(config));
}
 
debug('loaded!');
 
module.exports = middleware;