Meteor - Iron Router - can't parse urlencoded http request properly - meteor

I have a server-route set up that accepts POST requests from an external service (PayPal). I used to be able to get all the details by accessing this.request.body inside the action function of route, but after doing a meteor update recently, the request body is no longer being parsed correctly, and figuring out why is apparently way beyond my skill level.
I suppose I could roll back the updates to get everything to work again, but I'm trying to figure out what is going on.
So my question is: Why is the request body not being parsed correctly? Even just a nod in a general direction would be much appreciated, as I am clueless here.
My route looks like this:
this.route('ipnPay', {
path: '/ipn/pay',
where: 'server',
action: function() {
var request = this.request;
console.log(request.body);
//do other stuff
}
});
Which used to print out a response that looked like this:
I20150727-18:09:46.656(-4)? { payment_request_date: 'Mon Jul 27 15:09:12 PDT 2015',
I20150727-18:09:46.657(-4)? 'transaction[0].id_for_sender_txn': '9PB44643108585943',
I20150727-18:09:46.657(-4)? 'transaction[0].receiver': 'tom#example.com',
I20150727-18:09:46.657(-4)? 'transaction[0].is_primary_receiver': 'false',
I20150727-18:09:46.657(-4)? 'transaction[0].id': '2HH18284E5553225C',
I20150727-18:09:46.657(-4)? 'transaction[0].status': 'Completed',
I20150727-18:09:46.658(-4)? 'transaction[0].paymentType': 'PERSONAL',
I20150727-18:09:46.658(-4)? 'transaction[0].status_for_sender_txn': 'Completed',
I20150727-18:09:46.658(-4)? 'transaction[0].pending_reason': 'NONE',
I20150727-18:09:46.658(-4)? 'transaction[0].amount': 'USD 266.67' }
But after doing update, the request body is being parsed like this:
I20150727-18:32:35.812(-4)? { payment_request_date: 'Mon Jul 27 15:32:22 PDT 2015',
I20150727-18:32:35.813(-4)? transaction:
I20150727-18:32:35.813(-4)? { '0].id_for_sender_tx': '7WE57612VB713004Y',
I20150727-18:32:35.813(-4)? '0].receive': 'tom#example.com',
I20150727-18:32:35.813(-4)? '0].is_primary_receive': 'false',
I20150727-18:32:35.814(-4)? '0].i': '8B180259507549243',
I20150727-18:32:35.814(-4)? '0].statu': 'Completed',
I20150727-18:32:35.814(-4)? '0].paymentTyp': 'PERSONAL',
I20150727-18:32:35.814(-4)? '0].status_for_sender_tx': 'Completed',
I20150727-18:32:35.814(-4)? '0].pending_reaso': 'NONE',
I20150727-18:32:35.814(-4)? '0].amoun': 'USD 10.00' } }
So instead of the flat data structure in the first example, the parser is now trying create a nested transaction object. But key values are getting messed up..eg the first [ is being discarded as is the final character ( statu instead of status, typ instead of type, etc. )
Any ideas here??
The body of the actual actual request, that I obtained through ngrok is :
payment_request_date=Mon+Jul+27+15%3A09%3A12+PDT+2015&return_url=http%3A//localhost%3A3000/events/mHsWRFFnQSiX7zyem&fees_payer=SENDER&ipn_notification_url=http%3A//fnfndr.ngrok.io/ipn/pay&sender_email=xyz%40example.com&verify_sign=AqIeeetyNLVMnJSHSYCajOvN1y05Ai91xec8RhhiuUk10kK0d-xTI6gp&test_ipn=1&transaction%5B0%5D.id_for_sender_txn=9PB44643108585943&transaction%5B0%5D.receiver=tom%40example.com&cancel_url=http%3A//localhost%3A3000/events/mHsWRFFnQSiX7zyem&transaction%5B0%5D.is_primary_receiver=false&pay_key=AP-12T24911F3500884N&action_type=PAY&transaction%5B0%5D.id=2HH18284E5553225C&transaction%5B0%5D.status=Completed&transaction%5B0%5D.paymentType=PERSONAL&preapproval_key=PA-33150539CY900002V&transaction%5B0%5D.status_for_sender_txn=Completed&transaction%5B0%5D.pending_reason=NONE&transaction_type=Adaptive+Payment+PAY&transaction%5B0%5D.amount=USD+266.67&status=COMPLETED&log_default_shipping_address_in_transaction=false&charset=windows-1252&notify_version=UNVERSIONED&reverse_all_parallel_payments_on_error=false
And these were the packages that got updated when i ran meteor update:
bigdsk:inputmask upgraded from 3.1.42 to 3.1.63
gadicohen:sitemaps upgraded from 0.0.21 to 0.0.22
meteorhacks:kadira upgraded from 2.21.0 to 2.22.1
meteorhacks:kadira-profiler upgraded from 1.1.0 to 1.2.0
meteorhacks:npm upgraded from 1.3.0 to 1.4.0
meteorhacks:subs-manager upgraded from 1.4.0 to 1.5.2
momentjs:moment upgraded from 2.9.0 to 2.10.5
nemo64:bootstrap upgraded from 3.3.4_2 to 3.3.5_2
nemo64:bootstrap-data upgraded from 3.3.4_1 to 3.3.5
nimble:restivus upgraded from 0.6.6 to 0.8.1
simple:json-routes added, version 1.0.3
summernote:standalone upgraded from 0.6.7 to 0.6.13

This behavior has something to do with these two packages:
nimble:restivus upgraded from 0.6.6 to 0.8.1
simple:json-routes added, version 1.0.3
I don't fully understand how or why, but it is somehow interfering with the way iron:router normally parses HTTP requests.
So if you run into the same error, you can either downgrade or remove the packages above.

Related

How to send a file with RTK Query from Redux Toolkit?

I am trying to use RTK Query mutations to upload a file to the API. Here is my mutation code:
addBanner: builder.mutation({
query(body) {
return {
url: `/api/banners`,
method: 'POST',
body,
}
},
})
Here is how I generate the data for request.
const [addBanner, { isBannerLoading }] = useAddBannerMutation();
const new_banner = new FormData();
new_banner.append("file", my_file);
new_banner.append("type", my_type);
new_banner.append("title", my_title);
addBanner(new_banner).unwrap().then( () => ...
But I get an error:
A non-serializable value was detected in the state, in the path: `api.mutations.L-Mje7bYDfyNCC4NcxFD3.originalArgs.file`...
I know I can disable non-serializable check entirely through middleware, but I don't think it is an appropriate way of using Redux Toolkit and RTK. Without a file all works fine. Is there any right way of uploading files with RTK?
Edit: This has been fixed with #reduxjs/toolkit 1.6.1 - please update your package
I just opened an issue for this: https://github.com/reduxjs/redux-toolkit/issues/1239 - thanks for bringing it up!
For now, you'll probably have to disable that check (you can do so for a certain path in the state while keeping it for the rest with the ignoredPath option).

JS: firebase.init error: TypeError: Cannot read property 'database' of undefined

Am getting this error after following the steps mentioned in the nativescript-plugin-firebase readme file.
JS: firebase.init error: TypeError: Cannot read property 'database' of
undefined
https://github.com/EddyVerbruggen/nativescript-plugin-firebase
but i dont really understand nor do i know how to solve that.
the version of the plugin am using is : 6.4.0
with tns 4.1.2
EDIT: init code, from app.js
var firebase = require("nativescript-plugin-firebase");
firebase.init({ persist: true
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
function (instance) {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
I finally solved it by installing the plugin manually via the CLI (i initially installed it through NativeScript sidekick) apparently they didnt take in count the fact that some plugins may require some user inputs, to do write specific config file (which nativescript-plugin-firebase), so by installing it manually i got to provide the user input needed, it got configured and it worked!

JovoFramework - NEW_USER - tell is not a function

I'm using jovo framework (version 1.0.0) and I'm facing the following problem:
In app.js:
app.setHandler({
'NEW_USER': () => {
this.tell('Hello, I've just installed this skill.');
}
});
I get the following error when a user is new to the skill:
TypeError: this.tell is not a function
Can't I use this.tell in the NEW_USER?
System Environment:
Windows 10 Home
NodeJS: v8.9.1
I really appreciate any help you can provide.

Cordova firefoxos web access issue

I'm trying to port my properly working (in iOS, Android) cordova app to Firefoxos.
The simulator starts properly and its browser can load web pages BUT my app cannot load data from the web.
Looking at console I see the following errors:
"JavaScript error: app://aa2a2c24-a8d6-447d-92da-4f2e9af65661/plugins/org.apache.cordova.network-information/src/firefoxos/NetworkProxy.js, line 33: missing : after property id" simulator-process.js:44
"JavaScript error: app://aa2a2c24-a8d6-447d-92da-4f2e9af65661/cordova.js, line 1120: Module org.apache.cordova.network-information.NetworkProxy does not exist."
Any suggestion? Thanks.
Cordova 3.5.0
Simulator FirfeoxOS 1.3 and FirfeoxOS 1.4
After some research I figured out the issues
1- Despite upgrading cordova to 3.5.0 I must remember that plugins don't get automatically update.
To get the plugin code for firefoxos updated I added again the same plugin, removed the firefoxos platform and reinstalled it again.
At that point the javascript errors were gone
2- Then the ajax call were still not accessible due to permissions. To ensure you can have ajax call you have to put in your manifest.webapp the following code
"type": "privileged",
"permissions": {
"systemXHR": { "description": "Required for AJAX calls in app"}
}
Both "type" and "permissions" are needed
3- Finally you have to ensure the ajax calls use
mozSystem: true
Specifically for jquery, you could put something like the following on top of your js file:
if (device.platform == 'firefoxos') {
$.ajaxPrefilter( function( options ) {
if ( options.firefoxOS ) {
options.xhr = function() {
return new window.XMLHttpRequest( {
mozSystem: true
} );
}
}
} );
$.ajaxSetup( {
firefoxOS: true
} );
}
Now I can properly handle ajax calls.

How to handle confirm popup with phantomjs + behat + mink

In my tests I use this step to confirm a javascript confirm popup:
/**
* #when /^(?:|I )confirm the popup$/
*/
public function confirmPopup()
{
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}
This step work fine with selenium2 and chrome/firefox, but doesn't work with phantomjs.
How can I handle a confirm popup with phantomjs ?
for informations:
symfony: 2.0.23
behat: 2.4.6
mink: 1.5.0
Symfony2Extension: 1.0.2
MinkExtension: 1.1.4
MinkBrowserKitDriver: 1.1.0
MinkSelenium2Driver: 1.1.0
phamtomjs 1.9.1
behat.yml
default:
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
Behat\MinkExtension\Extension:
base_url: "http://localhost:8000/app_test.php"
default_session: selenium2
selenium2:
wd_host: "http://localhost:9876/wd/hub"
Thanks!
PS: Here the gist : https://gist.github.com/blazarecki/2888851
I updated my "Selenium2Driver.php" with the following:
public function acceptAlert()
{
$this->wdSession->accept_alert();
}
This makes the accept_alert() available for the driver.
So in the script, you could do something line this to accept the alert.
$this->getSession()->getDriver()->acceptAlert();
Note that I'm using the RawMinkContext not the native MinkContext
phantomjs is a headless browser, therefore all dialogs are not show and cannot be interacted with. A solution is to rewrite widnow.confirm and window.alert with your own functions that return pre-defined values.
Since a scenario runs within the same driver, it is perfectly safe to overwrite native methods with pre-defined return values (you will not have a situation where you really need to see a window within the same scenario). Moreover, it is safe to call these step definitions multiple times within a single scenario to flip returned value.
/**
* #When I accept confirmation dialogs
*/
public function acceptConfirmation() {
$this->getSession()->getDriver()->executeScript('window.confirm = function(){return true;}');
}
/**
* #When I do not accept confirmation dialogs
*/
public function acceptNotConfirmation() {
$this->getSession()->getDriver()->executeScript('window.confirm = function(){return false;}');
}
Scenario example:
Scenario: Removal of something with confirmation dialog
Given I accept confirmation dialogs
And I click a ".mylink" element
And I wait for AJAX to finish
And I should not see a ".some-removed-element" element

Resources