Skip to content

Commit

Permalink
Support relative paths in config json.
Browse files Browse the repository at this point in the history
  • Loading branch information
galbi101 committed Nov 12, 2017
1 parent ddebf8c commit da57634
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "server-with-benefits",
"author": "Gal Ben-Ishay <[email protected]>",
"version": "0.14.0",
"author": "Gal Ben-Ishay",
"version": "0.15.0",
"engines": {
"node": ">=0.10"
},
Expand All @@ -13,7 +13,7 @@
"body-parser": "~1.8.3",
"underscore": "~1.7.0",
"webpack": "^2.7.0",
"webpack-dev-middleware": "^1.11.0"
"webpack-dev-middleware": "^1.12.0"
},
"bin": {
"swb": "./bin/server"
Expand Down
10 changes: 6 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
var fs = require('fs');
var stripJsonComments = require('strip-json-comments');
var clc = require('cli-color');
var p = require('path');
var cwd = process.cwd();

const
ENV_VAR_KEY = 'SWB_CONF_FILE',
CONF_FILE = process.argv[2] || process.env[ENV_VAR_KEY] || (process.cwd() + '/swbConfig.json'),
CONF_FILE = (process.argv[2] && p.resolve(cwd, process.argv[2])) || process.env[ENV_VAR_KEY] || p.resolve(cwd, './swbConfig.json'),
// Console text styling
errorStyle = clc.red.bold,
headerStyle = clc.yellow.bold,
Expand Down Expand Up @@ -137,15 +139,15 @@ conf.servers.forEach(function(serverConf) {

}
if (serverConf.webpack) {
app.use(require('webpack-dev-middleware')(require('webpack')(require(serverConf.webpack.confFile))));
app.use(require('webpack-dev-middleware')(require('webpack')(require(p.resolve(cwd, serverConf.webpack.confFile)))));
}
else if (serverConf.static && serverConf.static.srcDir) {
if (serverConf.static.paths) {
for (var path in serverConf.paths) {
app.use(path, express.static(serverConf.static.srcDir + serverConf.static.paths[path]));
app.use(path, express.static(p.resolve(cwd, serverConf.static.srcDir + serverConf.static.paths[path])));
}
}
app.use(express.static(serverConf.static.srcDir));
app.use(express.static(p.resolve(cwd, serverConf.static.srcDir)));
}
app.listen(serverConf.port);
console.log(messages);
Expand Down

0 comments on commit da57634

Please sign in to comment.