Skip to content

Commit 223114d

Browse files
committed
First Commit
0 parents  commit 223114d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1424
-0
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# App artifacts
2+
/_build
3+
/db
4+
/deps
5+
/*.ez
6+
7+
# Generate on crash by the VM
8+
erl_crash.dump
9+
10+
# Static artifacts
11+
/node_modules
12+
13+
# Since we are building assets from web/static,
14+
# we ignore priv/static. You may want to comment
15+
# this depending on your deployment strategy.
16+
/priv/static/
17+
18+
# The config/prod.secret.exs file by default contains sensitive
19+
# data and you should not commit it into version control.
20+
#
21+
# Alternatively, you may comment the line below and commit the
22+
# secrets file as long as you replace its contents by environment
23+
# variables.
24+
/config/prod.secret.exs

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# BlogPhoenix
2+
3+
To start your Phoenix app:
4+
5+
1. Install dependencies with `mix deps.get`
6+
2. Create and migrate your database with `mix ecto.create && mix ecto.migrate`
7+
3. Start Phoenix endpoint with `mix phoenix.server`
8+
9+
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
10+
11+
Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).
12+
13+
## Learn more
14+
15+
* Official website: http://www.phoenixframework.org/
16+
* Guides: http://phoenixframework.org/docs/overview
17+
* Docs: http://hexdocs.pm/phoenix
18+
* Mailing list: http://groups.google.com/group/phoenix-talk
19+
* Source: https://github.com/phoenixframework/phoenix

brunch-config.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
exports.config = {
2+
// See http://brunch.io/#documentation for docs.
3+
files: {
4+
javascripts: {
5+
joinTo: "js/app.js"
6+
7+
// To use a separate vendor.js bundle, specify two files path
8+
// https://github.com/brunch/brunch/blob/stable/docs/config.md#files
9+
// joinTo: {
10+
// "js/app.js": /^(web\/static\/js)/,
11+
// "js/vendor.js": /^(web\/static\/vendor)|(deps)/
12+
// }
13+
//
14+
// To change the order of concatenation of files, explicitly mention here
15+
// https://github.com/brunch/brunch/tree/master/docs#concatenation
16+
// order: {
17+
// before: [
18+
// "web/static/vendor/js/jquery-2.1.1.js",
19+
// "web/static/vendor/js/bootstrap.min.js"
20+
// ]
21+
// }
22+
},
23+
stylesheets: {
24+
joinTo: "css/app.css"
25+
},
26+
templates: {
27+
joinTo: "js/app.js"
28+
}
29+
},
30+
31+
conventions: {
32+
// This option sets where we should place non-css and non-js assets in.
33+
// By default, we set this to "/web/static/assets". Files in this directory
34+
// will be copied to `paths.public`, which is "priv/static" by default.
35+
assets: /^(web\/static\/assets)/
36+
},
37+
38+
// Phoenix paths configuration
39+
paths: {
40+
// Dependencies and current project directories to watch
41+
watched: [
42+
"deps/phoenix/web/static",
43+
"deps/phoenix_html/web/static",
44+
"web/static",
45+
"test/static"
46+
],
47+
48+
// Where to compile files to
49+
public: "priv/static"
50+
},
51+
52+
// Configure your plugins
53+
plugins: {
54+
babel: {
55+
// Do not use ES6 compiler in vendor code
56+
ignore: [/web\/static\/vendor/]
57+
}
58+
},
59+
60+
modules: {
61+
autoRequire: {
62+
"js/app.js": ["web/static/js/app"]
63+
}
64+
},
65+
66+
npm: {
67+
enabled: true
68+
}
69+
};

config/config.exs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
use Mix.Config
7+
8+
# Configures the endpoint
9+
config :blog_phoenix, BlogPhoenix.Endpoint,
10+
url: [host: "localhost"],
11+
root: Path.dirname(__DIR__),
12+
secret_key_base: "FLiuTBuY0g8AyWVOv35IPJrLlAPAufrLdvFJnlWWJz0nvqY4E0TIITdub5nXMz2k",
13+
render_errors: [accepts: ~w(html json)],
14+
pubsub: [name: BlogPhoenix.PubSub,
15+
adapter: Phoenix.PubSub.PG2]
16+
17+
# Configures Elixir's Logger
18+
config :logger, :console,
19+
format: "$time $metadata[$level] $message\n",
20+
metadata: [:request_id]
21+
22+
# Import environment specific config. This must remain at the bottom
23+
# of this file so it overrides the configuration defined above.
24+
import_config "#{Mix.env}.exs"
25+
26+
# Configure phoenix generators
27+
config :phoenix, :generators,
28+
migration: true,
29+
binary_id: false

config/dev.exs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use Mix.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 use it
8+
# with brunch.io to recompile .js and .css sources.
9+
config :blog_phoenix, BlogPhoenix.Endpoint,
10+
http: [port: 4000],
11+
debug_errors: true,
12+
code_reloader: true,
13+
cache_static_lookup: false,
14+
check_origin: false,
15+
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin"]]
16+
17+
# Watch static and templates for browser reloading.
18+
config :blog_phoenix, BlogPhoenix.Endpoint,
19+
live_reload: [
20+
patterns: [
21+
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
22+
~r{web/views/.*(ex)$},
23+
~r{web/templates/.*(eex)$}
24+
]
25+
]
26+
27+
# Do not include metadata nor timestamps in development logs
28+
config :logger, :console, format: "[$level] $message\n"
29+
30+
# Set a higher stacktrace during development.
31+
# Do not configure such in production as keeping
32+
# and calculating stacktraces is usually expensive.
33+
config :phoenix, :stacktrace_depth, 20
34+
35+
# Configure your database
36+
config :blog_phoenix, BlogPhoenix.Repo,
37+
adapter: Ecto.Adapters.Postgres,
38+
username: "postgres",
39+
password: "postgres",
40+
database: "blog_phoenix_dev",
41+
hostname: "localhost",
42+
pool_size: 10

config/prod.exs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use Mix.Config
2+
3+
# For production, we configure the host to read the PORT
4+
# from the system environment. Therefore, you will need
5+
# to set PORT=80 before running your server.
6+
#
7+
# You should also configure the url host to something
8+
# meaningful, we use this information when generating URLs.
9+
#
10+
# Finally, we also include the path to a manifest
11+
# containing the digested version of static files. This
12+
# manifest is generated by the mix phoenix.digest task
13+
# which you typically run after static files are built.
14+
config :blog_phoenix, BlogPhoenix.Endpoint,
15+
http: [port: {:system, "PORT"}],
16+
url: [host: "example.com", port: 80],
17+
cache_static_manifest: "priv/static/manifest.json"
18+
19+
# Do not print debug messages in production
20+
config :logger, level: :info
21+
22+
# ## SSL Support
23+
#
24+
# To get SSL working, you will need to add the `https` key
25+
# to the previous section and set your `:url` port to 443:
26+
#
27+
# config :blog_phoenix, BlogPhoenix.Endpoint,
28+
# ...
29+
# url: [host: "example.com", port: 443],
30+
# https: [port: 443,
31+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
32+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
33+
#
34+
# Where those two env variables return an absolute path to
35+
# the key and cert in disk or a relative path inside priv,
36+
# for example "priv/ssl/server.key".
37+
#
38+
# We also recommend setting `force_ssl`, ensuring no data is
39+
# ever sent via http, always redirecting to https:
40+
#
41+
# config :blog_phoenix, BlogPhoenix.Endpoint,
42+
# force_ssl: [hsts: true]
43+
#
44+
# Check `Plug.SSL` for all available options in `force_ssl`.
45+
46+
# ## Using releases
47+
#
48+
# If you are doing OTP releases, you need to instruct Phoenix
49+
# to start the server for all endpoints:
50+
#
51+
# config :phoenix, :serve_endpoints, true
52+
#
53+
# Alternatively, you can configure exactly which server to
54+
# start per endpoint:
55+
#
56+
# config :blog_phoenix, BlogPhoenix.Endpoint, server: true
57+
#
58+
59+
# Finally import the config/prod.secret.exs
60+
# which should be versioned separately.
61+
import_config "prod.secret.exs"

config/test.exs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use Mix.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 :blog_phoenix, BlogPhoenix.Endpoint,
6+
http: [port: 4001],
7+
server: false
8+
9+
# Print only warnings and errors during test
10+
config :logger, level: :warn
11+
12+
# Configure your database
13+
config :blog_phoenix, BlogPhoenix.Repo,
14+
adapter: Ecto.Adapters.Postgres,
15+
username: "postgres",
16+
password: "postgres",
17+
database: "blog_phoenix_test",
18+
hostname: "localhost",
19+
pool: Ecto.Adapters.SQL.Sandbox

lib/blog_phoenix.ex

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
defmodule BlogPhoenix do
2+
use Application
3+
4+
# See http://elixir-lang.org/docs/stable/elixir/Application.html
5+
# for more information on OTP Applications
6+
def start(_type, _args) do
7+
import Supervisor.Spec, warn: false
8+
9+
children = [
10+
# Start the endpoint when the application starts
11+
supervisor(BlogPhoenix.Endpoint, []),
12+
# Start the Ecto repository
13+
worker(BlogPhoenix.Repo, []),
14+
# Here you could define other workers and supervisors as children
15+
# worker(BlogPhoenix.Worker, [arg1, arg2, arg3]),
16+
]
17+
18+
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
19+
# for other strategies and supported options
20+
opts = [strategy: :one_for_one, name: BlogPhoenix.Supervisor]
21+
Supervisor.start_link(children, opts)
22+
end
23+
24+
# Tell Phoenix to update the endpoint configuration
25+
# whenever the application is updated.
26+
def config_change(changed, _new, removed) do
27+
BlogPhoenix.Endpoint.config_change(changed, removed)
28+
:ok
29+
end
30+
end

lib/blog_phoenix/endpoint.ex

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
defmodule BlogPhoenix.Endpoint do
2+
use Phoenix.Endpoint, otp_app: :blog_phoenix
3+
4+
socket "/socket", BlogPhoenix.UserSocket
5+
6+
# Serve at "/" the static files from "priv/static" directory.
7+
#
8+
# You should set gzip to true if you are running phoenix.digest
9+
# when deploying your static files in production.
10+
plug Plug.Static,
11+
at: "/", from: :blog_phoenix, gzip: false,
12+
only: ~w(css fonts images js favicon.ico robots.txt)
13+
14+
# Code reloading can be explicitly enabled under the
15+
# :code_reloader configuration of your endpoint.
16+
if code_reloading? do
17+
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
18+
plug Phoenix.LiveReloader
19+
plug Phoenix.CodeReloader
20+
end
21+
22+
plug Plug.RequestId
23+
plug Plug.Logger
24+
25+
plug Plug.Parsers,
26+
parsers: [:urlencoded, :multipart, :json],
27+
pass: ["*/*"],
28+
json_decoder: Poison
29+
30+
plug Plug.MethodOverride
31+
plug Plug.Head
32+
33+
plug Plug.Session,
34+
store: :cookie,
35+
key: "_blog_phoenix_key",
36+
signing_salt: "ZiogktX3"
37+
38+
plug BlogPhoenix.Router
39+
end

lib/blog_phoenix/repo.ex

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
defmodule BlogPhoenix.Repo do
2+
use Ecto.Repo, otp_app: :blog_phoenix
3+
end

mix.exs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
defmodule BlogPhoenix.Mixfile do
2+
use Mix.Project
3+
4+
def project do
5+
[app: :blog_phoenix,
6+
version: "0.0.1",
7+
elixir: "~> 1.0",
8+
elixirc_paths: elixirc_paths(Mix.env),
9+
compilers: [:phoenix] ++ Mix.compilers,
10+
build_embedded: Mix.env == :prod,
11+
start_permanent: Mix.env == :prod,
12+
aliases: aliases,
13+
deps: deps]
14+
end
15+
16+
# Configuration for the OTP application.
17+
#
18+
# Type `mix help compile.app` for more information.
19+
def application do
20+
[mod: {BlogPhoenix, []},
21+
applications: [:phoenix, :phoenix_html, :cowboy, :logger,
22+
:phoenix_ecto, :postgrex]]
23+
end
24+
25+
# Specifies which paths to compile per environment.
26+
defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
27+
defp elixirc_paths(_), do: ["lib", "web"]
28+
29+
# Specifies your project dependencies.
30+
#
31+
# Type `mix help deps` for examples and options.
32+
defp deps do
33+
[{:phoenix, "~> 1.0.4"},
34+
{:phoenix_ecto, "~> 1.1"},
35+
{:postgrex, ">= 0.0.0"},
36+
{:phoenix_html, "~> 2.1"},
37+
{:phoenix_live_reload, "~> 1.0", only: :dev},
38+
{:cowboy, "~> 1.0"}]
39+
end
40+
41+
# Aliases are shortcut or tasks specific to the current project.
42+
# For example, to create, migrate and run the seeds file at once:
43+
#
44+
# $ mix ecto.setup
45+
#
46+
# See the documentation for `Mix` for more info on aliases.
47+
defp aliases do
48+
["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
49+
"ecto.reset": ["ecto.drop", "ecto.setup"]]
50+
end
51+
end

0 commit comments

Comments
 (0)