Skip to content

Commit

Permalink
Now it should be cross-platform compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
idanstark42 committed Jul 28, 2017
1 parent 1976a6b commit 9691b96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion localserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ var express = require('express');
var app = express();
var utils = require('./server_modules/utils');
var fileSystem = require('./server_modules/file_system');
var path = require('path');
var args = require('./server_modules/args');
var views = require('./server_modules/views');

var configs = [require('./server_modules/slave_mode')];

var middlewareLayers = [express.static(fileSystem.resolve('/src')),
var middlewareLayers = [express.static(fileSystem.resolve('src')),
require('./server_modules/sessions').middleware,
require('./server_modules/auth').basic(args.basicAuthCreds),
require('./server_modules/cors').middleware,
Expand Down
10 changes: 5 additions & 5 deletions server_modules/file_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var path = require('path')
var utils = require('./utils');
var args = require('./args');

function absoluteFile(file) {
return (file[0] === '/' ? utils.root : '') + file;
function absolutePath(file) {
return path.resolve(path.dirname(process.argv[1]), file);
}

function getDataFilePath(file) {
Expand All @@ -25,11 +25,11 @@ function parseFile(data) {
}

exports.resolve = function(file) {
return path.resolve(absoluteFile(file));
return path.resolve(absolutePath(file));
};

exports.readFile = function(file) {
file = absoluteFile(file);
file = absolutePath(file);

return Q.promise(function(resolve,reject) {
fs.exists(file,function(exists) {
Expand Down Expand Up @@ -57,7 +57,7 @@ exports.parseDataFile = function(file) {
};

exports.writeFile = function(file, contents, cb) {
file = absoluteFile(file);
file = absolutePath(file);

var dir = path.dirname(file);
mkdirp(dir, function(err) {
Expand Down
4 changes: 2 additions & 2 deletions server_modules/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ exports.route = function(app) {

app.get('/',function(req,res) {
req.session.user = 'user';
res.sendFile(fileSystem.resolve('/index.html'));
res.sendFile(fileSystem.resolve('index.html'));
});

app.get('/admin',function(req,res) {
req.session.user = 'admin';
res.sendFile(fileSystem.resolve('/index.html'));
res.sendFile(fileSystem.resolve('index.html'));
});

};

0 comments on commit 9691b96

Please sign in to comment.