spserver: Fixed critical file path bug
This commit is contained in:
parent
051b6d40dc
commit
fbda0adf62
3 changed files with 8 additions and 7 deletions
|
@ -4,14 +4,13 @@ var fs = require('fs');
|
|||
var http = require('http');
|
||||
var _ = require('lodash');
|
||||
var nStatic = require('node-static');
|
||||
var root = require('app-root-path');
|
||||
var path = require('path');
|
||||
|
||||
|
||||
var config = require('./config');
|
||||
var logger = require('./logger');
|
||||
|
||||
var env = config.get('NODE_ENV');
|
||||
var fileServer = new nStatic.Server(config.get('serve') || config.get(env + ':serve'));
|
||||
|
||||
var spserver = function(settings) {
|
||||
if (!settings) {
|
||||
|
@ -21,7 +20,9 @@ var spserver = function(settings) {
|
|||
settings[env] = {};
|
||||
}
|
||||
|
||||
var base = generateBase(settings.file || settings[env].file, settings);
|
||||
var fileServer = new nStatic.Server(path.resolve(settings.serve || settings[env].server));
|
||||
|
||||
var base = generateBase(path.resolve(settings.file || settings[env].file), settings);
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
logger.debug('[REQ] GET:', req.url);
|
||||
|
@ -67,10 +68,10 @@ function generateBase(file, settings) {
|
|||
}
|
||||
|
||||
if (_.endsWith(file, 'js')) {
|
||||
return require(root.resolve(file));
|
||||
return require(file);
|
||||
}
|
||||
|
||||
var contents = fs.readFileSync(root.resolve(file));
|
||||
var contents = fs.readFileSync(file);
|
||||
|
||||
if (settings.template || settings[env] && settings[env].template) {
|
||||
contents = _.template(contents)(settings);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
},
|
||||
"homepage": "https://github.com/TheThing/spserver",
|
||||
"dependencies": {
|
||||
"app-root-path": "^1.0.0",
|
||||
"bunyan": "^1.3.3",
|
||||
"lodash": "^3.0.1",
|
||||
"nconf": "^0.7.1",
|
||||
|
|
|
@ -25,8 +25,9 @@ describe('spserver', function() {
|
|||
});
|
||||
|
||||
it('should return function if file is javascript', function() {
|
||||
var path = require('path');
|
||||
var nothing = require('./nothing');
|
||||
var test = spserver.generateBase('test/nothing.js', {});
|
||||
var test = spserver.generateBase(path.resolve('test/nothing.js'), {});
|
||||
|
||||
assert.strictEqual(nothing.toString(), test.toString());
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue