From fbda0adf62d0ccfe964a811b29c749e50090c61e Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Wed, 4 Feb 2015 08:33:17 +0000 Subject: [PATCH] spserver: Fixed critical file path bug --- lib/spserver.js | 11 ++++++----- package.json | 1 - test/base.test.js | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/spserver.js b/lib/spserver.js index 7326180..0f58b63 100644 --- a/lib/spserver.js +++ b/lib/spserver.js @@ -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); diff --git a/package.json b/package.json index 43373af..7405f25 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/base.test.js b/test/base.test.js index 4e8702e..93cd57c 100644 --- a/test/base.test.js +++ b/test/base.test.js @@ -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()); });