Skip to content

Commit

Permalink
Merge pull request #147 from dwyl/update-elixir-v1.12-issue-145
Browse files Browse the repository at this point in the history
update deps #146
  • Loading branch information
SimonLab committed Oct 12, 2021
2 parents 5d04424 + de63efe commit 820b80c
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 183 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: elixir
elixir:
- 1.10.4
- 1.12.3
otp_release:
- 23.0.3
- 24.0.2
services:
- postgresql
env:
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: mix phx.server
5 changes: 0 additions & 5 deletions assets/.babelrc

This file was deleted.

34 changes: 19 additions & 15 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// We need to import the CSS so that webpack will load it.
// The MiniCssExtractPlugin is used to separate it out into
// its own CSS file.
import css from '../css/app.css';
// We import the CSS which is extracted to its own file by esbuild.
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
import "../css/app.css"

// webpack automatically bundles all modules in your
// entry points. Those entry points can be configured
// in "webpack.config.js".
//
// Import dependencies
//
import 'phoenix_html';
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
import "phoenix_html"
// Establish Phoenix Socket and LiveView configuration.
import {Socket} from "phoenix"
import {LiveSocket} from "phoenix_live_view"

// Import local files
//
// Local files can be imported directly using relative paths, for example:
// import socket from "./socket"
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})

// connect if there are any LiveViews on the page
liveSocket.connect()

// expose liveSocket on window for web console debug logs and latency simulation:
// >> liveSocket.enableDebug()
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
// >> liveSocket.disableLatencySim()
window.liveSocket = liveSocket
24 changes: 0 additions & 24 deletions assets/package.json

This file was deleted.

43 changes: 0 additions & 43 deletions assets/webpack.config.js

This file was deleted.

10 changes: 10 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ config :joken, default_signer: System.get_env("SECRET_KEY_BASE")
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"

# https://gist.github.com/chrismccord/2ab350f154235ad4a4d0f4de6decba7b
# Configure esbuild (the version is required)
config :esbuild,
version: "0.12.18",
default: [
args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
12 changes: 3 additions & 9 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ config :auth, AuthWeb.Endpoint,
code_reloader: true,
check_origin: false,
watchers: [
node: [
"node_modules/webpack/bin/webpack.js",
"--mode",
"development",
"--watch-stdin",
cd: Path.expand("../assets", __DIR__)
]
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}
]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
Expand Down Expand Up @@ -73,4 +67,4 @@ config :logger, :console, format: "[$level] $message\n"
config :phoenix, :stacktrace_depth, 20

# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime
config :phoenix, :plug_init_mode, :runtime
7 changes: 6 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ config :auth, Auth.Repo,
# you can enable the server option below.
config :auth, AuthWeb.Endpoint,
http: [port: 4002],
server: false
server: true # https://elixirforum.com/t/wallaby-with-phoenix-1-16-rc0/42352/9

# Print only warnings and errors during test
config :logger, level: :warn

config :elixir_auth_google,
client_id: "631770888008-6n0oruvsm16kbkqg6u76p5cv5kfkcekt.apps.googleusercontent.com",
client_secret: "MHxv6-RGF5nheXnxh1b0LNDq",
httpoison_mock: true
4 changes: 3 additions & 1 deletion coveralls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"test/",
"lib/auth/application.ex",
"lib/auth_web.ex",
"lib/auth_web/views/error_helpers.ex"
"lib/auth_web/views/error_helpers.ex",
"lib/auth_web/channels/user_socket.ex",
"lib/auth_web/telemetry.ex"
]
}
10 changes: 7 additions & 3 deletions elixir_buildpack.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Elixir version
elixir_version=1.10.4
elixir_version=1.12.3

# Erlang version
# available versions https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds/blob/master/otp-versions
erlang_version=23.0.3
erlang_version=23.3.2

# always_rebuild=true
always_rebuild=true

# Invoke assets.deploy defined in your mix.exs to deploy assets with esbuild
# Note we nuke the esbuild executable from the image
hook_post_compile="eval mix assets.deploy && rm -f _build/esbuild"
15 changes: 9 additions & 6 deletions lib/auth/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ defmodule Auth.Application do

use Application

@impl true
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Start the Ecto repository
Auth.Repo,
# Start the endpoint when the application starts
# Start the Telemetry supervisor
AuthWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: Auth.PubSub},
# Start the Endpoint (http/https)
AuthWeb.Endpoint
# Starts a worker by calling: Auth.Worker.start_link(arg)
# {Auth.Worker, arg},
# Start a worker by calling: Auth.Worker.start_link(arg)
# {Auth.Worker, arg}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand All @@ -25,12 +28,12 @@ defmodule Auth.Application do

# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
# Sadly this is untestable hence ignoring it.

# coveralls-ignore-start
@impl true
def config_change(changed, _new, removed) do
AuthWeb.Endpoint.config_change(changed, removed)
:ok
end

# coveralls-ignore-stop
end
3 changes: 3 additions & 0 deletions lib/auth/mailer.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Auth.Mailer do
use Swoosh.Mailer, otp_app: :auth
end
45 changes: 39 additions & 6 deletions lib/auth_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,38 @@ defmodule AuthWeb do
namespace: AuthWeb

# Import convenience functions from controllers
import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
import Phoenix.Controller,
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]

# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
# Include shared imports and aliases for views
unquote(view_helpers())
end
end

import AuthWeb.ErrorHelpers
import AuthWeb.Gettext
alias AuthWeb.Router.Helpers, as: Routes
def live_view do
quote do
use Phoenix.LiveView,
layout: {AuthWeb.LayoutView, "live.html"}

unquote(view_helpers())
end
end

def live_component do
quote do
use Phoenix.LiveComponent

unquote(view_helpers())
end
end

def router do
quote do
use Phoenix.Router

import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end

Expand All @@ -60,6 +76,23 @@ defmodule AuthWeb do
end
end

defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML

# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
import Phoenix.LiveView.Helpers

# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View

import AuthWeb.ErrorHelpers
import AuthWeb.Gettext
alias AuthWeb.Router.Helpers, as: Routes
end
end

@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
Expand Down
1 change: 1 addition & 0 deletions lib/auth_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ defmodule AuthWeb.AuthController do
def google_handler(conn, %{"code" => code, "state" => state}) do
{:ok, token} = ElixirAuthGoogle.get_token(code, conn)
{:ok, profile} = ElixirAuthGoogle.get_user_profile(token.access_token)

# save profile to people:
app_id = get_app_id(state)
person = Person.create_google_person(Map.merge(profile, %{app_id: app_id}))
Expand Down
17 changes: 12 additions & 5 deletions lib/auth_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ defmodule AuthWeb.Endpoint do
signing_salt: "Fir8x4nA"
]

socket "/socket", AuthWeb.UserSocket,
websocket: true,
longpoll: false
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]

# socket "/socket", AuthWeb.UserSocket,
# websocket: true,
# longpoll: false

# Serve at "/" the static files from "priv/static" directory.
#
Expand All @@ -22,16 +24,21 @@ defmodule AuthWeb.Endpoint do
at: "/",
from: :auth,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
only: ~w(assets fonts images favicon.ico robots.txt)

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :auth
end

plug Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"

plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

Expand All @@ -44,4 +51,4 @@ defmodule AuthWeb.Endpoint do
plug Plug.Head
plug Plug.Session, @session_options
plug AuthWeb.Router
end
end
Loading

0 comments on commit 820b80c

Please sign in to comment.