Skip to content

Commit

Permalink
recreate router when the service url is different than original
Browse files Browse the repository at this point in the history
  • Loading branch information
pofider committed May 22, 2015
1 parent 28b3db3 commit bf84750
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/odataServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var Router = require("./router.js");
var prune = require("./prune.js");

function ODataServer(serviceUrl) {
this.serviceUrl = serviceUrl;

this.cfg = {
serviceUrl: serviceUrl,
afterRead: function() {},
Expand All @@ -40,9 +42,11 @@ ODataServer.prototype.handle = function (req, res) {
if (!this.cfg.serviceUrl && !req.protocol)
throw new Error("Unable to determine service url from the express request or value provided in the ODataServer constructor.");

this.cfg.serviceUrl = this.cfg.serviceUrl || (req.protocol + '://' + req.get('host') + req.originalUrl.replace(req.url, ""));
if (!this.router) {
this.router = new Router(url.parse(this.cfg.serviceUrl).pathname);
this.cfg.serviceUrl = this.serviceUrl ? this.serviceUrl : (req.protocol + '://' + req.get('host') + req.originalUrl.replace(req.url, ""));

var prefix = url.parse(this.cfg.serviceUrl).pathname;
if (!this.router || (prefix !== this.router.prefix)) {
this.router = new Router(prefix);
this._initializeRoutes();
}

Expand Down Expand Up @@ -125,7 +129,7 @@ ODataServer.prototype.executeQuery = function (col, query, cb) {
var self = this;
this.cfg.beforeQuery(col, query, function (err) {
if (err)
return cb(err);
return cb(err);

self.cfg.query(col, query, function(err, res) {
if (err)
Expand Down

0 comments on commit bf84750

Please sign in to comment.