Skip to content
Permalink
Browse files

Add Phoenix app

  • Loading branch information...
picandocodigo committed Dec 11, 2017
1 parent cc25892 commit c8de5d363d18bdc3c3e712780edcc68d92abcfbd
Showing with 4,282 additions and 0 deletions.
  1. +27 −0 apps/phoenix_app/.gitignore
  2. +19 −0 apps/phoenix_app/README.md
  3. +62 −0 apps/phoenix_app/assets/brunch-config.js
  4. +1 −0 apps/phoenix_app/assets/css/app.css
  5. +77 −0 apps/phoenix_app/assets/css/phoenix.css
  6. +21 −0 apps/phoenix_app/assets/js/app.js
  7. +62 −0 apps/phoenix_app/assets/js/socket.js
  8. +3,266 −0 apps/phoenix_app/assets/package-lock.json
  9. +18 −0 apps/phoenix_app/assets/package.json
  10. BIN apps/phoenix_app/assets/static/favicon.ico
  11. BIN apps/phoenix_app/assets/static/images/phoenix.png
  12. +5 −0 apps/phoenix_app/assets/static/robots.txt
  13. +27 −0 apps/phoenix_app/config/config.exs
  14. +49 −0 apps/phoenix_app/config/dev.exs
  15. +64 −0 apps/phoenix_app/config/prod.exs
  16. +10 −0 apps/phoenix_app/config/test.exs
  17. +9 −0 apps/phoenix_app/lib/phoenix_app.ex
  18. +29 −0 apps/phoenix_app/lib/phoenix_app/application.ex
  19. +67 −0 apps/phoenix_app/lib/phoenix_app_web.ex
  20. +37 −0 apps/phoenix_app/lib/phoenix_app_web/channels/user_socket.ex
  21. +7 −0 apps/phoenix_app/lib/phoenix_app_web/controllers/page_controller.ex
  22. +57 −0 apps/phoenix_app/lib/phoenix_app_web/endpoint.ex
  23. +24 −0 apps/phoenix_app/lib/phoenix_app_web/gettext.ex
  24. +26 −0 apps/phoenix_app/lib/phoenix_app_web/router.ex
  25. +35 −0 apps/phoenix_app/lib/phoenix_app_web/templates/layout/app.html.eex
  26. +36 −0 apps/phoenix_app/lib/phoenix_app_web/templates/page/index.html.eex
  27. +40 −0 apps/phoenix_app/lib/phoenix_app_web/views/error_helpers.ex
  28. +17 −0 apps/phoenix_app/lib/phoenix_app_web/views/error_view.ex
  29. +3 −0 apps/phoenix_app/lib/phoenix_app_web/views/layout_view.ex
  30. +3 −0 apps/phoenix_app/lib/phoenix_app_web/views/page_view.ex
  31. +47 −0 apps/phoenix_app/mix.exs
  32. +11 −0 apps/phoenix_app/priv/gettext/en/LC_MESSAGES/errors.po
  33. +10 −0 apps/phoenix_app/priv/gettext/errors.pot
  34. +8 −0 apps/phoenix_app/test/phoenix_app_web/controllers/page_controller_test.exs
  35. +21 −0 apps/phoenix_app/test/phoenix_app_web/views/error_view_test.exs
  36. +3 −0 apps/phoenix_app/test/phoenix_app_web/views/layout_view_test.exs
  37. +3 −0 apps/phoenix_app/test/phoenix_app_web/views/page_view_test.exs
  38. +33 −0 apps/phoenix_app/test/support/channel_case.ex
  39. +34 −0 apps/phoenix_app/test/support/conn_case.ex
  40. +2 −0 apps/phoenix_app/test/test_helper.exs
  41. +12 −0 mix.lock
@@ -0,0 +1,27 @@
# App artifacts
/_build
/db
/deps
/*.ez

# Generated on crash by the VM
erl_crash.dump

# Generated on crash by NPM
npm-debug.log

# Static artifacts
/assets/node_modules

# Since we are building assets from assets/,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/

# Files matching config/*.secret.exs pattern contain sensitive
# data and you should not commit them into version control.
#
# Alternatively, you may comment the line below and commit the
# secrets files as long as you replace their contents by environment
# variables.
/config/*.secret.exs
@@ -0,0 +1,19 @@
# PhoenixApp

To start your Phoenix server:

* Install dependencies with `mix deps.get`
* Install Node.js dependencies with `cd assets && npm install`
* Start Phoenix endpoint with `mix phx.server`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).

## Learn more

* Official website: http://www.phoenixframework.org/
* Guides: http://phoenixframework.org/docs/overview
* Docs: https://hexdocs.pm/phoenix
* Mailing list: http://groups.google.com/group/phoenix-talk
* Source: https://github.com/phoenixframework/phoenix
@@ -0,0 +1,62 @@
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: "js/app.js"

// To use a separate vendor.js bundle, specify two files path
// http://brunch.io/docs/config#-files-
// joinTo: {
// "js/app.js": /^js/,
// "js/vendor.js": /^(?!js)/
// }
//
// To change the order of concatenation of files, explicitly mention here
// order: {
// before: [
// "vendor/js/jquery-2.1.1.js",
// "vendor/js/bootstrap.min.js"
// ]
// }
},
stylesheets: {
joinTo: "css/app.css"
},
templates: {
joinTo: "js/app.js"
}
},

conventions: {
// This option sets where we should place non-css and non-js assets in.
// By default, we set this to "/assets/static". Files in this directory
// will be copied to `paths.public`, which is "priv/static" by default.
assets: /^(static)/
},

// Phoenix paths configuration
paths: {
// Dependencies and current project directories to watch
watched: ["static", "css", "js", "vendor"],
// Where to compile files to
public: "../priv/static"
},

// Configure your plugins
plugins: {
babel: {
// Do not use ES6 compiler in vendor code
ignore: [/vendor/]
}
},

modules: {
autoRequire: {
"js/app.js": ["js/app"]
}
},

npm: {
enabled: true
}
};
@@ -0,0 +1 @@
/* This file is for your main application css. */

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,21 @@
// Brunch automatically concatenates all files in your
// watched paths. Those paths can be configured at
// config.paths.watched in "brunch-config.js".
//
// However, those files will only be executed if
// explicitly imported. The only exception are files
// in vendor, which are never wrapped in imports and
// therefore are always executed.

// Import dependencies
//
// If you no longer want to use a dependency, remember
// to also remove its path from "config.paths.watched".
import "phoenix_html"

// Import local files
//
// Local files can be imported directly using relative
// paths "./socket" or full ones "web/static/js/socket".

// import socket from "./socket"
@@ -0,0 +1,62 @@
// NOTE: The contents of this file will only be executed if
// you uncomment its entry in "assets/js/app.js".

// To use Phoenix channels, the first step is to import Socket
// and connect at the socket path in "lib/web/endpoint.ex":
import {Socket} from "phoenix"

let socket = new Socket("/socket", {params: {token: window.userToken}})

// When you connect, you'll often need to authenticate the client.
// For example, imagine you have an authentication plug, `MyAuth`,
// which authenticates the session and assigns a `:current_user`.
// If the current user exists you can assign the user's token in
// the connection for use in the layout.
//
// In your "lib/web/router.ex":
//
// pipeline :browser do
// ...
// plug MyAuth
// plug :put_user_token
// end
//
// defp put_user_token(conn, _) do
// if current_user = conn.assigns[:current_user] do
// token = Phoenix.Token.sign(conn, "user socket", current_user.id)
// assign(conn, :user_token, token)
// else
// conn
// end
// end
//
// Now you need to pass this token to JavaScript. You can do so
// inside a script tag in "lib/web/templates/layout/app.html.eex":
//
// <script>window.userToken = "<%= assigns[:user_token] %>";</script>
//
// You will need to verify the user token in the "connect/2" function
// in "lib/web/channels/user_socket.ex":
//
// def connect(%{"token" => token}, socket) do
// # max_age: 1209600 is equivalent to two weeks in seconds
// case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
// {:ok, user_id} ->
// {:ok, assign(socket, :user, user_id)}
// {:error, reason} ->
// :error
// end
// end
//
// Finally, pass the token on connect as below. Or remove it
// from connect if you don't care about authentication.

socket.connect()

// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("topic:subtopic", {})
channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })

export default socket
Oops, something went wrong.

0 comments on commit c8de5d3

Please sign in to comment.
You can’t perform that action at this time.