dwyl / dwylbot

:robot: Automating our GitHub Workflow to improve team communication/collaboration and reduce tedious repetition!
28 stars 7 forks source link

Different payloads received for dev and prod environment? #19

Closed SimonLab closed 7 years ago

SimonLab commented 7 years ago

Some context: Each time an event appears on Github (new label, new issue,...) my server receive a POST request from Github with all the information of the event store in the payload (body) of the request. The format of the paylod seems however different on my loacalhost and on Heroku:

On Heroku the payload received is already parse to Json:

Parameters: %{"action" => "unlabeled", "issue" => %{"assignee" => nil,...

On localhost the payload as the following format:

{ payload: '{"action":"unlabeled","issue":...

The the first one is a json object, the second one is also a json object but with just one property "payload" which has for value the stringify response. Which means that on localhost I need to use Poinon.decode to parse the value but this will break on production has the value is already parsed.

I've also deploy an hapi server on Heroku to see the format of the payload and it match the second version;

{ payload: '{"action":"unlabeled","issue":...

I'm not entirely sure why this difference exists and where it comes form, is it the way Github send the payload? Is it an option on Phoenix to parse automatically the payload on production but not on developement? Does anyone has any suggestion to help me understand how Phoenix manage the payload of a post request and why there is this difference in the format of the payload?

nelsonic commented 7 years ago

@SimonLab which version of Elixir are you running on your Localhost vs. Heroku?

SimonLab commented 7 years ago

@nelsonic

Localhost: Elixir 1.3.4

from elixir_buildpack:

erlang_version=18.3
elixir_version=1.3.4
always_rebuild=false
runtime_path=/app

The phoenix version is defined on the mix.exs and is phoenix, "~> 1.2.1" so it should be the same on localhost and Heroku

SimonLab commented 7 years ago

Not a blocker anymore as I'm creating a switch to parse the payload properly depending on its format. But I still would like to understand the source of the problem :worried:

SimonLab commented 7 years ago

Ok, just being silly!! content-type

When you create a webhooks check that select the right content type!! "application/json" and not "application/x-www-form-urlencoded"

I will remember this one now!

nelsonic commented 7 years ago

@SimonLab this should be included in the readme/instructions for setting up web hooks...