Skip to content

Commit

Permalink
Workaround circular dependency and fix invalid json response.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
cdaniel committed Aug 18, 2015
1 parent 9c56d83 commit 6f866e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 5 additions & 7 deletions server/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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 = [];
Expand Down
10 changes: 6 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6f866e8

Please sign in to comment.