Skip to content

Commit

Permalink
example with maybe improved line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Sep 9, 2018
1 parent 97481cd commit db747cb
Show file tree
Hide file tree
Showing 24 changed files with 386 additions and 12 deletions.
17 changes: 17 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The directory Mix will write compiled artifacts to.
/_build

# If you run "mix test --cover", coverage assets end up here.
/cover

# The directory Mix downloads your dependencies sources to.
/deps

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez
10 changes: 10 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Demo

- Install dependencies with `mix deps.get`
- Start your service with `iex -S mix`
- Run project test suite with `mix test`

## Learn more

- Raxx documentation: https://hexdocs.pm/raxx
- Slack channel: https://elixir-lang.slack.com/messages/C56H3TBH8/
4 changes: 4 additions & 0 deletions demo/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use Mix.Config

config :exsync,
extra_extensions: [".js", ".css"]
2 changes: 2 additions & 0 deletions demo/lib/demo.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defmodule Demo do
end
45 changes: 45 additions & 0 deletions demo/lib/demo/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule Demo.Application do
@moduledoc false

use Application

def start(_type, _args) do

config = %{}
cleartext_options = [port: port(), cleartext: true]
secure_options = [port: secure_port(), cleartext: :false, certfile: certificate_path(), keyfile: certificate_key_path()]

children = [
Supervisor.child_spec({Demo.WWW, [config, cleartext_options]}, id: :www_cleartext),
Supervisor.child_spec({Demo.WWW, [config, secure_options]}, id: :www_secure),

]

opts = [strategy: :one_for_one, name: Demo.Supervisor]
Supervisor.start_link(children, opts)
end

defp port() do
with raw when is_binary(raw) <- System.get_env("PORT"), {port, ""} = Integer.parse(raw) do
port
else
_ -> 8080
end
end

defp secure_port() do
with raw when is_binary(raw) <- System.get_env("SECURE_PORT"), {secure_port, ""} = Integer.parse(raw) do
secure_port
else
_ -> 8443
end
end

defp certificate_path() do
Application.app_dir(:demo, "priv/localhost/certificate.pem")
end

defp certificate_key_path() do
Application.app_dir(:demo, "priv/localhost/certificate_key.pem")
end
end
Binary file added demo/lib/demo/public/favicon.ico
Binary file not shown.
62 changes: 62 additions & 0 deletions demo/lib/demo/public/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Reset */
body {
margin: 0;
}

/* Make everything a border-box, because why not? */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}

html {
min-height: 100%;
}

body {
font-family: 'Roboto', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
/* Currently ems cause chrome bug misinterpreting rems on body element */
font-size: 1.6em;
font-weight: 300;
letter-spacing: .01em;
line-height: 1.6;
color: white;

/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#45484d+0,000000+100 */
background: rgb(69,72,77); /* Old browsers */
background: -moz-linear-gradient(right , rgba(69,72,77,1) 0%, rgba(0,0,0,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(right, rgba(69,72,77,1) 0%,rgba(0,0,0,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to left, rgba(69,72,77,1) 0%,rgba(0,0,0,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#45484d', endColorstr='#000000',GradientType=0 ); /* IE6-9 */

}

h1 {
margin: 0;
font-size: 6.6rem;
font-weight: 300;
line-height: 1.2;
}

.centered {
margin-left: auto;
margin-right: auto;
max-width: 80rem;
}

.accent {
border-left: #00ff9c 2px solid;
margin: 50px;
padding: 30px;
}

nav {
letter-spacing: 1.5em
}

nav a {
color: #00ff9c;
letter-spacing: 0.05em
}
5 changes: 5 additions & 0 deletions demo/lib/demo/public/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
window.app = {
show: function (title) {
console.log(title)
}
}
13 changes: 13 additions & 0 deletions demo/lib/demo/www.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Demo.WWW do
use Ace.HTTP.Service, port: 8080, cleartext: true

use Raxx.Router, [
{%{path: []}, Demo.WWW.HomePage},
{_, Demo.WWW.NotFoundPage}
]

@external_resource "lib/demo/public/main.css"
@external_resource "lib/demo/public/main.js"
# use Raxx.Static, "./public"
use Raxx.Logger, level: :info
end
25 changes: 25 additions & 0 deletions demo/lib/demo/www/home_page.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Demo.WWW.HomePage do
use Raxx.Server
use Demo.WWW.Layout, arguments: [:title]

@impl Raxx.Server
def handle_request(_request = %{method: :GET}, _state) do
title = "Raxx.Kit"

response(:ok)
|> render(title)
end

def handle_request(request = %{method: :POST}, _state) do
case URI.decode_query(request.body) do
%{"name" => name} ->
greeting = "Hello, #{name}!"

response(:ok)
|> render(greeting)
_ ->
response(:bad_request)
|> render("Bad Request")
end
end
end
23 changes: 23 additions & 0 deletions demo/lib/demo/www/home_page.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<main class="centered">
<section class="accent">
<h1><%= title %></h1>
<form action="/" method="post">
<label>
<span>tell us your name</span>
<input type="text" name="name" value="" autofocus>
</label>
<button type="submit">Submit</button>
</form>
<h2>Find out more</h2>
<nav>
<a href="https://github.com/CrowdHailer/raxx">SOURCE CODE</a>
<a href="https://elixir-lang.slack.com/messages/C56H3TBH8/">CHAT</a>
</nav>
<%= javascript_variables title: title %>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
app.show(title)
})
</script>
</section>
</main>
3 changes: 3 additions & 0 deletions demo/lib/demo/www/layout.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Demo.WWW.Layout do
use Raxx.Layout
end
14 changes: 14 additions & 0 deletions demo/lib/demo/www/layout.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>demo</title>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="/main.css">
<link rel="icon" href="/favicon.ico">
</head>
<body>
<%= __content__ %>
<script type="text/javascript" src="/main.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions demo/lib/demo/www/not_found_page.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Demo.WWW.NotFoundPage do
use Raxx.Server
use Demo.WWW.Layout, arguments: [:value]

@impl Raxx.Server
def handle_request(_request, _state) do
response(:not_found)
|> render(0)
end

def foo(value) do
5 / value
end
end
9 changes: 9 additions & 0 deletions demo/lib/demo/www/not_found_page.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<main class="centered">
<section class="accent">
<h1>Nothing here!</h1>



<%= foo(value) %>
</section>
</main>
28 changes: 28 additions & 0 deletions demo/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Demo.Mixfile do
use Mix.Project

def project do
[
app: :demo,
version: "0.1.0",
elixir: "~> 1.7.1",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

def application do
[extra_applications: [:logger], mod: {Demo.Application, []}]
end

defp deps do
[
{:ace, "~> 0.16.8"},
{:raxx, path: "../", override: true},
{:raxx_static, "~> 0.6.1"},
{:jason, "~> 1.0.0"},
{:exsync, "~> 0.2.3", only: :dev}
]
end
end
11 changes: 11 additions & 0 deletions demo/mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%{
"ace": {:hex, :ace, "0.16.8", "e50e28884d06e44306c941c030b878c82e89f4389f68b373d781cdb0ce68d6ec", [:mix], [{:hpack, "~> 0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}, {:raxx, "~> 0.15.7", [hex: :raxx, repo: "hexpm", optional: false]}], "hexpm"},
"cookie": {:hex, :cookie, "0.1.1", "89438362ee0f0ed400e9f076d617d630f82d682e3fbcf767072a46a6e1ed5781", [:mix], [], "hexpm"},
"exsync": {:hex, :exsync, "0.2.3", "a1ac11b4bd3808706003dbe587902101fcc1387d9fc55e8b10972f13a563dd15", [:mix], [{:file_system, "~> 0.2", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"hpack": {:hex, :hpack_erl, "0.2.3", "17670f83ff984ae6cd74b1c456edde906d27ff013740ee4d9efaa4f1bf999633", [:rebar3], [], "hexpm"},
"jason": {:hex, :jason, "1.0.1", "ef108e64c6e086364b9f15b0073cf794061670af8f331d545d7308c0ba2e67f9", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
"raxx": {:hex, :raxx, "0.15.11", "3ea6eb85712d1d0fb566affda0bdf44cf62e1affc599872f8fe3eac589129016", [:mix], [{:cookie, "~> 0.1.0", [hex: :cookie, repo: "hexpm", optional: false]}, {:jason, "~> 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"raxx_static": {:hex, :raxx_static, "0.6.1", "8b48254fc3d1b8b1e473b7c307fbba0ae767c60482754ce823c664544c85d729", [:mix], [{:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:raxx, "~> 0.15.2", [hex: :raxx, repo: "hexpm", optional: false]}], "hexpm"},
}
20 changes: 20 additions & 0 deletions demo/priv/localhost/certificate.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDPjC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f1u19WfUxlC3GPh45hSFZ/g+Hz8
OxDc8YfSk8VAjJHu2ap7G9+G
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions demo/priv/localhost/certificate_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAmNvyeepIRsAm6QuUezhFf3KXTygBoYX4oYMfXb6ZklDQ8QAT
9BrsYUW1+QDDHPF3foDa+k4Mm8XL6/yHqQFutnhqqYysd/XovCG1ff7Vq0TpX7GA
HGEvrTj/Q63xqVOmyZINgvi9TfRTIKZ5LIo6O0dV5LSv6cLTXa8bFBxybigTxL+H
gzY0e3kQzuFSYLOxvLCd4j7YnTzOsYY8M49mNRDbja4SkDcRxqV0mJDUkUxayaDW
XY06eY1RtiYHFeZQF/2iEKBnsm62VJcFiq/vnjNkc1SBxqIoXE7BrRe+yLi1TniM
ds8gGDUX0QqnhbuG/USuB0ev0VZNg+LiUYA/dQIDAQABAoIBAQCOfA9ExzbCBGEA
wFOSnDxj9UvHdDI4/ulonBIDzyPVeFGbJAh1dRc8AMAEMEqvUwGgwLndsh0cor5X
5dgKmJQ7sHk0PDWTyHw9yWok3QMMl7q2AX26dnj7jfKbgquNu7TvlZ3UpMnIvWMz
Pxoag2qOUQtmmWqUio99dzjVgULFHFOufcSfPsM1s71BhcZwcssG2JxmbjsG8r1w
wR80p1VQjWzQdBe5Kgc+ZZZidf1SSW3W65zrdAV3tT9A78hmTdvhdXG9SOTu3Vt8
Eab1eAewfds0FGJtUIzpJe6DCWFBnpAsGbWCf2CMkPRhWcLHVFN8jHO6KpKdqq0b
bjXmZTAhAoGBAMZdXGqpFQWD73nVqrbdyZhtDU8VCAeT0d5XmlNQwvVPyPch50FL
zDt2H9k6+Ko3p8wjSIWdKFvsqYuCFbBI8Lf4b3+Tu2Vi9ajFrnHyGUlB0X1Ny+nt
iXpAUYCsGnp6hylzkNCGMQXQ55oDVjXr8/m/M8QpsGbAicu05HLuene5AoGBAMVF
0pyZNhjNBiJ/p/9AR1Rao8jWC5e70jxXdqX3kbWzobD1+qNEEP0klpnJGUIMASTb
P99OrY5Fo1bxJecLjrwpQU63d90erAnirq7luIjQnXHAT6lg7CZX4uNW+P/iqc8p
bvmcue6ptWf4HPtqtLpxXzbAlAA6SN5UDpFLbuudAoGAGaVOYnfTwO/K0Uyfkp7g
BnXq55OHgztIQd+/kw/49LBJAjJ+7IE5OWLPQU2PgqpJZmoVYTjtU90oGmJKHY2A
mbhj6fGWo8gEjLpqEE9Fl6QLypB5UZglUwnnv6QAlF8tBF3tlhgTVHYqy02tIrGL
zHk83xqotNAlwJF1i6praPkCgYABMGGLlhTQY3P1A0X08OM9K+quzDN3r6cdu/04
FNzo9nM0CNeA4mkjzXOm66JeVoovOa8R3nyHTf4lCQEMenJayfjdy5dKWuP4j0g0
P6g0EuXQCLOyNqZVuNPiQOTxTeFuITbNBFfOi3FPdhxem48JTKOhRdnegntr85++
2nCJtQKBgE9wMkBbQGKQxgV1VtNuLdhBPrCnvFvInX+/M5eaOLmg9IeDWER1vv5m
kHbAa6t+jvi70ZQPrwMmAVT6YawpUuR7Ttaga/QMThw0dSvUuiPLXPno3ZZl9GM4
OwKJHTSsqQf3jIT86Bm3wh375B8Dw0PPJUtraAkE4ioidTKuDnD4
-----END RSA PRIVATE KEY-----
17 changes: 17 additions & 0 deletions demo/priv/localhost/certificate_signing_request.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE REQUEST-----
MIICpjCCAY4CAQAwYTELMAkGA1UEBhMCVUsxDzANBgNVBAgMBkxvbmRvbjEPMA0G
A1UEBwwGTG9uZG9uMRwwGgYDVQQKDBNXb3Jrc2hvcCAxNCBMaW1pdGVkMRIwEAYD
VQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCY
2/J56khGwCbpC5R7OEV/cpdPKAGhhfihgx9dvpmSUNDxABP0GuxhRbX5AMMc8Xd+
gNr6Tgybxcvr/IepAW62eGqpjKx39ei8IbV9/tWrROlfsYAcYS+tOP9DrfGpU6bJ
kg2C+L1N9FMgpnksijo7R1XktK/pwtNdrxsUHHJuKBPEv4eDNjR7eRDO4VJgs7G8
sJ3iPtidPM6xhjwzj2Y1ENuNrhKQNxHGpXSYkNSRTFrJoNZdjTp5jVG2JgcV5lAX
/aIQoGeybrZUlwWKr++eM2RzVIHGoihcTsGtF77IuLVOeIx2zyAYNRfRCqeFu4b9
RK4HR6/RVk2D4uJRgD91AgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAQEAXlpo5GxS
oAavAybmPwlPYq9UekjsucRUx7q8MdI9+6JFgVZkJ47NZeq1ynuFM0QFGWC3Sbyx
q0yKD3/UHIItta/4nQev366jAfi2Se6IE9RYYcmly36joHUB0MtceLYEGwazJbaB
yq5nI0wgLDlQ318Uh9g+rc0DAohuEm+Guvq5xIVOXrkidhlPOiSHcXtIgGzHbfnz
oir5rhtRgpCgulFq18ZWeQpIZ1UvTz0QbPvnnUZiVDxQVvKHwdRAjtVoJmuD9fuz
F1ZiqKQWe4nqEw5pJuCK5tBdquB9hlWxaJhs/sR4dhcrjvX+8VxbGGaLlJV2mcrA
EheSjS4N675U3w==
-----END CERTIFICATE REQUEST-----
15 changes: 15 additions & 0 deletions demo/test/demo/www/home_page_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Demo.WWW.HomePageTest do
use ExUnit.Case

alias Demo.WWW.HomePage

test "returns the Raxx.Kit home page" do
request = Raxx.request(:GET, "/")

response = HomePage.handle_request(request, %{})

assert response.status == 200
assert response.headers == [{"content-type", "text/html"}]
assert String.contains?(response.body, "Raxx.Kit")
end
end
5 changes: 5 additions & 0 deletions demo/test/demo_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule DemoTest do
use ExUnit.Case
doctest Demo

end
1 change: 1 addition & 0 deletions demo/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
Loading

0 comments on commit db747cb

Please sign in to comment.