Skip to content

Commit d510ac5

Browse files
committed
init
0 parents  commit d510ac5

23 files changed

+659
-0
lines changed

.formatter.exs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
import_deps: [:phoenix],
3+
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/
24+
25+
# Ignore package tarball (built via "mix hex.build").
26+
imogen-*.tar
27+

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Imogen
2+
3+
To start your Phoenix server:
4+
5+
* Run `mix setup` to install and setup dependencies
6+
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
7+
8+
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
9+
10+
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
11+
12+
## Learn more
13+
14+
* Official website: https://www.phoenixframework.org/
15+
* Guides: https://hexdocs.pm/phoenix/overview.html
16+
* Docs: https://hexdocs.pm/phoenix
17+
* Forum: https://elixirforum.com/c/phoenix-forum
18+
* Source: https://github.com/phoenixframework/phoenix

config/config.exs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
7+
# General application configuration
8+
import Config
9+
10+
config :imogen,
11+
generators: [timestamp_type: :utc_datetime]
12+
13+
# Configures the endpoint
14+
config :imogen, ImogenWeb.Endpoint,
15+
url: [host: "localhost"],
16+
adapter: Bandit.PhoenixAdapter,
17+
render_errors: [
18+
formats: [json: ImogenWeb.ErrorJSON],
19+
layout: false
20+
],
21+
pubsub_server: Imogen.PubSub,
22+
live_view: [signing_salt: "k0UQX1ob"]
23+
24+
# Configures Elixir's Logger
25+
config :logger, :console,
26+
format: "$time $metadata[$level] $message\n",
27+
metadata: [:request_id]
28+
29+
# Use Jason for JSON parsing in Phoenix
30+
config :phoenix, :json_library, Jason
31+
32+
# Import environment specific config. This must remain at the bottom
33+
# of this file so it overrides the configuration defined above.
34+
import_config "#{config_env()}.exs"

config/dev.exs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Config
2+
3+
# For development, we disable any cache and enable
4+
# debugging and code reloading.
5+
#
6+
# The watchers configuration can be used to run external
7+
# watchers to your application. For example, we can use it
8+
# to bundle .js and .css sources.
9+
config :imogen, ImogenWeb.Endpoint,
10+
# Binding to loopback ipv4 address prevents access from other machines.
11+
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
12+
http: [ip: {127, 0, 0, 1}, port: 4000],
13+
check_origin: false,
14+
code_reloader: true,
15+
debug_errors: true,
16+
secret_key_base: "LaxjQV41mxTAbnjlzIRA4Ohx5vUZRtL6MKuB4wbFYH16WYkEob+zjUREOSFx0WuZ",
17+
watchers: []
18+
19+
# ## SSL Support
20+
#
21+
# In order to use HTTPS in development, a self-signed
22+
# certificate can be generated by running the following
23+
# Mix task:
24+
#
25+
# mix phx.gen.cert
26+
#
27+
# Run `mix help phx.gen.cert` for more information.
28+
#
29+
# The `http:` config above can be replaced with:
30+
#
31+
# https: [
32+
# port: 4001,
33+
# cipher_suite: :strong,
34+
# keyfile: "priv/cert/selfsigned_key.pem",
35+
# certfile: "priv/cert/selfsigned.pem"
36+
# ],
37+
#
38+
# If desired, both `http:` and `https:` keys can be
39+
# configured to run both http and https servers on
40+
# different ports.
41+
42+
# Enable dev routes for dashboard and mailbox
43+
config :imogen, dev_routes: true
44+
45+
# Do not include metadata nor timestamps in development logs
46+
config :logger, :console, format: "[$level] $message\n"
47+
48+
# Set a higher stacktrace during development. Avoid configuring such
49+
# in production as building large stacktraces may be expensive.
50+
config :phoenix, :stacktrace_depth, 20
51+
52+
# Initialize plugs at runtime for faster development compilation
53+
config :phoenix, :plug_init_mode, :runtime

config/prod.exs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Config
2+
3+
# Do not print debug messages in production
4+
config :logger, level: :info
5+
6+
# Runtime production configuration, including reading
7+
# of environment variables, is done on config/runtime.exs.

config/runtime.exs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import Config
2+
3+
# config/runtime.exs is executed for all environments, including
4+
# during releases. It is executed after compilation and before the
5+
# system starts, so it is typically used to load production configuration
6+
# and secrets from environment variables or elsewhere. Do not define
7+
# any compile-time configuration in here, as it won't be applied.
8+
# The block below contains prod specific runtime configuration.
9+
10+
# ## Using releases
11+
#
12+
# If you use `mix release`, you need to explicitly enable the server
13+
# by passing the PHX_SERVER=true when you start it:
14+
#
15+
# PHX_SERVER=true bin/imogen start
16+
#
17+
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18+
# script that automatically sets the env var above.
19+
if System.get_env("PHX_SERVER") do
20+
config :imogen, ImogenWeb.Endpoint, server: true
21+
end
22+
23+
if config_env() == :prod do
24+
# The secret key base is used to sign/encrypt cookies and other secrets.
25+
# A default value is used in config/dev.exs and config/test.exs but you
26+
# want to use a different value for prod and you most likely don't want
27+
# to check this value into version control, so we use an environment
28+
# variable instead.
29+
secret_key_base =
30+
System.get_env("SECRET_KEY_BASE") ||
31+
raise """
32+
environment variable SECRET_KEY_BASE is missing.
33+
You can generate one by calling: mix phx.gen.secret
34+
"""
35+
36+
host = System.get_env("PHX_HOST") || "example.com"
37+
port = String.to_integer(System.get_env("PORT") || "4000")
38+
39+
config :imogen, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
40+
41+
config :imogen, ImogenWeb.Endpoint,
42+
url: [host: host, port: 443, scheme: "https"],
43+
http: [
44+
# Enable IPv6 and bind on all interfaces.
45+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
46+
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
47+
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
48+
ip: {0, 0, 0, 0, 0, 0, 0, 0},
49+
port: port
50+
],
51+
secret_key_base: secret_key_base
52+
53+
# ## SSL Support
54+
#
55+
# To get SSL working, you will need to add the `https` key
56+
# to your endpoint configuration:
57+
#
58+
# config :imogen, ImogenWeb.Endpoint,
59+
# https: [
60+
# ...,
61+
# port: 443,
62+
# cipher_suite: :strong,
63+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
64+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
65+
# ]
66+
#
67+
# The `cipher_suite` is set to `:strong` to support only the
68+
# latest and more secure SSL ciphers. This means old browsers
69+
# and clients may not be supported. You can set it to
70+
# `:compatible` for wider support.
71+
#
72+
# `:keyfile` and `:certfile` expect an absolute path to the key
73+
# and cert in disk or a relative path inside priv, for example
74+
# "priv/ssl/server.key". For all supported SSL configuration
75+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
76+
#
77+
# We also recommend setting `force_ssl` in your config/prod.exs,
78+
# ensuring no data is ever sent via http, always redirecting to https:
79+
#
80+
# config :imogen, ImogenWeb.Endpoint,
81+
# force_ssl: [hsts: true]
82+
#
83+
# Check `Plug.SSL` for all available options in `force_ssl`.
84+
end

config/test.exs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Config
2+
3+
# We don't run a server during test. If one is required,
4+
# you can enable the server option below.
5+
config :imogen, ImogenWeb.Endpoint,
6+
http: [ip: {127, 0, 0, 1}, port: 4002],
7+
secret_key_base: "wcS8n88EJMstUaObtLbAZSBm8LwzH6R2wT/yLMsifQvxFxrez6p2BZ6WE7xFAUJr",
8+
server: false
9+
10+
# Print only warnings and errors during test
11+
config :logger, level: :warning
12+
13+
# Initialize plugs at runtime for faster test compilation
14+
config :phoenix, :plug_init_mode, :runtime

lib/imogen.ex

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Imogen do
2+
@moduledoc """
3+
Imogen keeps the contexts that define your domain
4+
and business logic.
5+
6+
Contexts are also responsible for managing your data, regardless
7+
if it comes from the database, an external API or others.
8+
"""
9+
end

lib/imogen/application.ex

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defmodule Imogen.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
use Application
7+
8+
@impl true
9+
def start(_type, _args) do
10+
children = [
11+
ImogenWeb.Telemetry,
12+
{DNSCluster, query: Application.get_env(:imogen, :dns_cluster_query) || :ignore},
13+
{Phoenix.PubSub, name: Imogen.PubSub},
14+
# Start a worker by calling: Imogen.Worker.start_link(arg)
15+
# {Imogen.Worker, arg},
16+
# Start to serve requests, typically the last entry
17+
ImogenWeb.Endpoint
18+
]
19+
20+
# See https://hexdocs.pm/elixir/Supervisor.html
21+
# for other strategies and supported options
22+
opts = [strategy: :one_for_one, name: Imogen.Supervisor]
23+
Supervisor.start_link(children, opts)
24+
end
25+
26+
# Tell Phoenix to update the endpoint configuration
27+
# whenever the application is updated.
28+
@impl true
29+
def config_change(changed, _new, removed) do
30+
ImogenWeb.Endpoint.config_change(changed, removed)
31+
:ok
32+
end
33+
end

lib/imogen_web.ex

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
defmodule ImogenWeb do
2+
@moduledoc """
3+
The entrypoint for defining your web interface, such
4+
as controllers, components, channels, and so on.
5+
6+
This can be used in your application as:
7+
8+
use ImogenWeb, :controller
9+
use ImogenWeb, :html
10+
11+
The definitions below will be executed for every controller,
12+
component, etc, so keep them short and clean, focused
13+
on imports, uses and aliases.
14+
15+
Do NOT define functions inside the quoted expressions
16+
below. Instead, define additional modules and import
17+
those modules here.
18+
"""
19+
20+
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
21+
22+
def router do
23+
quote do
24+
use Phoenix.Router, helpers: false
25+
26+
# Import common connection and controller functions to use in pipelines
27+
import Plug.Conn
28+
import Phoenix.Controller
29+
end
30+
end
31+
32+
def channel do
33+
quote do
34+
use Phoenix.Channel
35+
end
36+
end
37+
38+
def controller do
39+
quote do
40+
use Phoenix.Controller,
41+
formats: [:html, :json],
42+
layouts: [html: ImogenWeb.Layouts]
43+
44+
import Plug.Conn
45+
46+
unquote(verified_routes())
47+
end
48+
end
49+
50+
def verified_routes do
51+
quote do
52+
use Phoenix.VerifiedRoutes,
53+
endpoint: ImogenWeb.Endpoint,
54+
router: ImogenWeb.Router,
55+
statics: ImogenWeb.static_paths()
56+
end
57+
end
58+
59+
@doc """
60+
When used, dispatch to the appropriate controller/live_view/etc.
61+
"""
62+
defmacro __using__(which) when is_atom(which) do
63+
apply(__MODULE__, which, [])
64+
end
65+
end
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule ImogenWeb.ErrorJSON do
2+
@moduledoc """
3+
This module is invoked by your endpoint in case of errors on JSON requests.
4+
5+
See config/config.exs.
6+
"""
7+
8+
# If you want to customize a particular status code,
9+
# you may add your own clauses, such as:
10+
#
11+
# def render("500.json", _assigns) do
12+
# %{errors: %{detail: "Internal Server Error"}}
13+
# end
14+
15+
# By default, Phoenix returns the status message from
16+
# the template name. For example, "404.json" becomes
17+
# "Not Found".
18+
def render(template, _assigns) do
19+
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
20+
end
21+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule ImogenWeb.ResizeController do
2+
use ImogenWeb, :controller
3+
4+
def show(conn, %{"image_url" => image_url, "size" => size}) do
5+
image = Req.get!(image_url)
6+
7+
{:ok, original} = Image.from_binary(image.body)
8+
{:ok, thumbnail} = Image.thumbnail(original, size, autorotate: true)
9+
10+
thumbnail_path = Briefly.create!(extname: ".jpg")
11+
12+
{:ok, _image_ref} = Image.write(thumbnail, thumbnail_path)
13+
14+
conn
15+
|> put_resp_content_type("image/jpeg")
16+
|> send_file(200, thumbnail_path)
17+
end
18+
end

0 commit comments

Comments
 (0)