Packages

FaultTree is a library for performing [fault tree analysis](https://en.wikipedia.org/wiki/Fault_tree_analysis). It includes a small HTTP server capable of graphing the resulting FTA, or returning it as JSON.

Current section

Files

Jump to
fault_tree lib fault_tree router.ex
Raw

lib/fault_tree/router.ex

defmodule FaultTree.Router do
@moduledoc """
Handler for HTTP requests.
"""
use Trot.Router
use Trot.Template
static "/js", "js"
get "/" do
render_template("upload.html.eex", [])
end
post "/analyze" do
tree = conn.body_params
|> Map.get("contents")
|> FaultTree.parse()
|> FaultTree.to_json()
case Map.get(conn.body_params, "output") do
"json" -> tree
"html" -> render_template("graph.html.eex", [tree: tree])
_ -> :bad_request
end
end
import_routes Trot.NotFound
end