From 6f866e8fb173a7235340bd3fe5c2c3e9d15b217a Mon Sep 17 00:00:00 2001 From: Krzysztof Daniel Date: Tue, 18 Aug 2015 18:41:54 +0200 Subject: [PATCH] Workaround circular dependency and fix invalid json response. The share module has a circular dependency with maps, and those should be separated. Workaround for now will do. POST response must return a valid json, as we currently handle errors in a map update (and redirect to login page). --- server/maps.js | 12 +++++------- server/server.js | 10 ++++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/maps.js b/server/maps.js index 60373b7..63773c5 100644 --- a/server/maps.js +++ b/server/maps.js @@ -182,9 +182,8 @@ var mapmodule = function(db, share) { res.statusCode = 500; res.send(JSON.stringify(err)); } else { - res.writeHead(200, { - 'content-type' : 'text/html' - }); + res.setHeader('Content-Type', 'application/json'); + res.send(JSON.stringify({})); res.end(); } }); @@ -237,9 +236,8 @@ var mapmodule = function(db, share) { res.statusCode = 500; res.send(JSON.stringify(err)); } else { - res.writeHead(200, { - 'content-type' : 'text/html' - }); + res.setHeader('Content-Type', 'application/json'); + res.send(JSON.stringify({})); res.end(); } }); @@ -278,7 +276,7 @@ var mapmodule = function(db, share) { if (!maps[0].anonymousShare) { maps[0].anonymousShare = false; } else { - maps[0].anonymousShareLink = share.constructSharingURL(req, mapId); + maps[0].anonymousShareLink = share[0].constructSharingURL(req, mapId); } if(!maps[0].preciseShare){ maps[0].preciseShare = []; diff --git a/server/server.js b/server/server.js index ff09ebd..0074cdc 100755 --- a/server/server.js +++ b/server/server.js @@ -89,13 +89,15 @@ var WardleyMapsApp = function(configOptions) { var userProvider = require('./user-provider')(app); - self.db = require('./db')(configOptions.databaseConnectionString); + var share = [null]; + + self.db = require('./db')(configOptions.databaseConnectionString); self.exportmap = new require('./export')(self.db); - self.maps = new require('./maps')(self.db, self.share); + self.maps = new require('./maps')(self.db, share); - var share = require('./router/share.js')('/share', self.db, userProvider.loginRequired, self.maps, self.exportmap); + share[0] = require('./router/share.js')('/share', self.db, userProvider.loginRequired, self.maps, self.exportmap); - app.use('/share', share.router); + app.use('/share', share[0].router); app.use('/profile', userProvider.loginRequired, require('./router/profilerouter.js')().router); app.use('/api', userProvider.authenticationRequired, require('./router/apirouter.js')(self.maps, self.exportmap).router); app.use('/', userProvider.loginRequired, require('./router/mainrouter.js')(self.maps).router);