Node-Force.com-REST-Demo icon indicating copy to clipboard operation
Node-Force.com-REST-Demo copied to clipboard

Possible routing error

Open jfeigel opened this issue 11 years ago • 0 comments

I downloaded and configured the code in both my local environment (wamp) and with a Heroku developer account using our SalesForce sandbox and when I run the application I get the following error:

TypeError: Cannot call method 'indexOf' of undefined
    at ServerResponse.res.redirect (C:\wamp\www\node\node_modules\express\lib\response.js:403:13)
    at EventEmitter.<anonymous> (C:\wamp\www\node\oauth.js:61:19)
    at EventEmitter.emit (events.js:117:20)
    at EventEmitter.mixin._respond (C:\wamp\www\node\node_modules\restler\lib\restler.js:125:36)
    at EventEmitter.mixin._fireEvents (C:\wamp\www\node\node_modules\restler\lib\restler.js:136:10)
    at IncomingMessage.<anonymous> (C:\wamp\www\node\node_modules\restler\lib\restler.js:118:17)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:895:16
    at process._tickCallback (node.js:415:13)

So after trying to trace it back I ended up editing oauth.js in rest.post.on() to check the state before the redirect:

if(state != undefined) {
    console.log('oauth done - redirecting to '+state);
    res.redirect(state);
}
else {
    console.log('state undefined');
}

Then when I ran the application it was able to render the first page, https://test-sfdc.herokuapp.com/, but when I try to click the link (List of 10 Accounts) I get the following:

oauth done - redirecting to /
state undefined
state undefined
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (http.js:704:11)
    at ServerResponse.res.setHeader (C:\wamp\www\node\node_modules\express\node_modules\connect\lib\patch.js:62:20)
    at next (C:\wamp\www\node\node_modules\express\node_modules\connect\lib\http.js:172:13)
    at Object.callback (C:\wamp\www\node\app.js:32:6)
    at EventEmitter.rest.request.on.on.options.refresh.options.oauth.access_token (C:\wamp\www\node\rest.js:23:13)
    at EventEmitter.emit (events.js:117:20)
    at EventEmitter.mixin._respond (C:\wamp\www\node\node_modules\restler\lib\restler.js:127:12)
    at EventEmitter.mixin._fireEvents (C:\wamp\www\node\node_modules\restler\lib\restler.js:136:10)
    at IncomingMessage.<anonymous> (C:\wamp\www\node\node_modules\restler\lib\restler.js:118:17)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)

Any thoughts?

jfeigel avatar May 13 '13 17:05 jfeigel