'use strict';

/** @module express-webapp-assets/server */

var
    _ = require('lodash'),
    express = require('express'),
    serveStatic = require('serve-static'),
    assets = require('./middleware'),
    debug = require('debug')('express-webapp-assets:server'),
    DEBUG = debug.enabled;

/**
 * simple http server for external API server written in other frameworks/languages.
 *
 * @param {AssetsConfig} config
 * @param {string} [config.host='localhost']
 * @param {number} [config.port=3000]
 * @param {string} [config.root='./public']
 * @param {string} [config.mount='/']
 * @param {function} [callback] for `express.application.listen`
 * @returns {express.application}
 */
module.exports = function (config, callback) {
    config = _.merge({
        host: 'localhost',
        port: 3000,
        root: './public',
        mount: '/'
    }, config);

    console.log('start server on', config.host + ':' + config.port + config.mount);

    express()
        .use(serveStatic(config.root))
        .use(config.mount, assets(config))
        .listen(config.port, config.host, callback);
};


@@ -57,16 +57,44 @@
 */%0A%0Avar%0A
+    path = require('path'),%0A
     _ = 
@@ -896,18 +896,21 @@
     
-console.lo
+DEBUG && debu
 g('s
@@ -975,24 +975,34 @@
 mount);%0A%0A   
+ var app =
  express()%0A 
@@ -1025,16 +1025,44 @@
 eStatic(
+path.resolve(process.cwd(), 
 config.r
@@ -1066,16 +1066,17 @@
 g.root))
+)
 %0A       
@@ -1161,15 +1161,72 @@
 callback
+ && function () %7B%0A            callback(config);%0A        %7D
 );%0A%7D;%0A%0A

fix to return config to callback.