Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIM-864 mongoosepush exposes phoenix initial endpoint #144

Merged

Conversation

leszke
Copy link
Contributor

@leszke leszke commented Mar 20, 2020

From story description:

As MongoosePush Client (HTTP API user)

Given MongoosePush is running

When I send a dummy POST request to MongoosePush on Phoenix backed endpoint

Then I get dummy response

Notes:

  • Both HTTP and HTTPS protocols should be supported

  • Both HTTP 1.1 and HTTP 2.0 protocols should be supported

  • Temporary we need to expose those two endpoints on different ports then current API

  • Phoenix should be configured with no Ecto and no Views.

  • Phoenix Websockets should be disabled

  • No need for exposing new endpoints in release Docker container

  • Dummy Controller and dummy entry in Router should be created in order to propose initial file structure - we need to keep in mind protocol versions split etc.

@leszke leszke requested review from michalwski and rslota March 20, 2020 10:20
Copy link
Contributor

@rslota rslota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! In general, the code does what it suppose to, just few minor things to change, mostly formatting. I'm not sure if mix format has been used here, if not, let's do so.
Quite a few files are missing newline character at the end of last line - if that was intentional, I recommend this read: https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file :)

config/dev.exs Outdated
debug_errors: true,
code_reloader: false,
check_origin: false,
server: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing end-of-line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unintentional and corrected with mix format. Anyway thank you for comprehensive reading :)

@@ -32,7 +32,7 @@ defmodule MongoosePush.Application do
MongoosePush.Telemetry.attach_all()

# Define workers and child supervisors to be supervised
children = children()
children = children() ++ [MongoosePushWeb.Endpoint]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's rename children to service_children or something like that in order to indicate that those are not "all possible children" anymore.

@@ -0,0 +1,7 @@
defmodule MongoosePushWeb.DummyController do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses 4 spaces indentation, while other use double. We should normalize to double-spaces.

def handle(conn, params) do
json(conn, %{body: params})
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing end-of-line character.

#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
plug Plug.Static,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need any static data, so we can remove this plug.

@@ -0,0 +1,13 @@
defmodule MongoosePushWeb.DummyControllerTest do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses 4 spaces indentation, while other use double. We should normalize to double-spaces.

conn = post(conn, "/api/dummy", [key: "value"])
assert json_response(conn,200) == %{"body" => %{"key"=>"value"}}
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing end-of-line character.

@@ -0,0 +1,2 @@
{:ok, _} = Application.ensure_all_started(:mongoose_push)
ExUnit.start()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing end-of-line character.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's recommended to use ExUnit.start(capture: true) in order to hide logs as long tests are green.

Copy link
Contributor

@michalwski michalwski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @leszke! I left some comments to parts of the code which I think is not required by MongoosePush and a question regarding Phoenix's JSON library.

Comment on lines 7 to 11
@session_options [
store: :cookie,
key: "_mongoose_push_key",
signing_salt: "URIBGSwL"
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, we don't need this in MongoosePush since there is no session needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rslota what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems that we can remove this along with entire Plug.Session.

Comment on lines 17 to 21
plug Plug.Static,
at: "/",
from: :mongoose_push,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is also not needed. We'll probably don't have static files to serve.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rslota what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, also left comment for that :)

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what is the default json encoder? I don't see it configured and I think it's better to use the one which is already used in the project. As far as I know MongoosePush already uses Jason. It can be configured by adding the following line:

config :phoenix, :json_library, Jason

to config/config.exs

@michalwski michalwski merged commit 1089ab9 into master Mar 20, 2020
@leszke leszke deleted the mim-864-mongoosepush-exposes-phoenix-initial-endpoint branch March 23, 2020 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants