diff --git a/Dockerfile b/Dockerfile index ed17cfc..028aac7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM elixir:1.9-slim as build -WORKDIR /root/shortnr/service +WORKDIR /root/shortnr COPY . . RUN mix local.hex --force @@ -11,7 +11,7 @@ RUN env MIX_ENV=prod mix release FROM debian:buster-20191014-slim WORKDIR /home/shortnr -COPY --from=build /root/shortnr/service/_build/prod/rel/service/ . +COPY --from=build /root/shortnr/_build/prod/rel/service/ . RUN apt-get update && apt-get install -y --no-install-recommends \ libtinfo5=6.1+20181013-2+deb10u2 \ diff --git a/config/config.exs b/config/config.exs index 984e20c..ceceb7a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -5,4 +5,9 @@ config :service, config :logger, :console, format: "date=$date time=$time level=$level$levelpad message=\"$message\" $metadata\n", - metadata: [:port, :file, :line, :crash_reason, :stack] + metadata: [:port, :file, :line, :crash_reason, :stack], + level: + (fn + :prod -> :info + _ -> :debug + end).(Mix.env()) diff --git a/lib/router.ex b/lib/router.ex index ce5c1f5..5778a3e 100644 --- a/lib/router.ex +++ b/lib/router.ex @@ -46,7 +46,7 @@ defmodule Shortnr.Router do end def handle_errors(conn, %{kind: _kind, reason: reason, stack: stack}) do - Logger.error(inspect(reason), stack: inspect(stack)) + Logger.error(reason, stack: stack) {:error, {:internal_server_error, "internal server error"}, conn} |> Text.encode_response() diff --git a/lib/url/repo/dets.ex b/lib/url/repo/dets.ex index 18dae67..016575e 100644 --- a/lib/url/repo/dets.ex +++ b/lib/url/repo/dets.ex @@ -3,7 +3,10 @@ defmodule Shortnr.URL.Repo.DETS do @impl true def get(key) do - {:ok, :dets.lookup(:urls, key) |> List.first() |> elem(1)} + case :dets.lookup(:urls, key) |> List.first() do + {_, url} -> {:ok, url} + nil -> {:ok, nil} + end end @impl true diff --git a/lib/url/url.ex b/lib/url/url.ex index b888184..69e721c 100644 --- a/lib/url/url.ex +++ b/lib/url/url.ex @@ -8,7 +8,12 @@ defmodule Shortnr.URL do updated_at: DateTime.utc_now(), url: %URI{} - @type t :: %__MODULE__{id: String.t(), url: URI.t()} + @type t :: %__MODULE__{ + id: String.t(), + url: URI.t(), + created_at: DateTime.t(), + updated_at: DateTime.t() + } @spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error() def create(url, repo) do