[
  {
    "path": ".gitignore",
    "content": "example/*.js\nelm-stuff/\n.DS_Store\nnode_modules/\nelm.js\n.comp\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015 Isaac Shapira\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# Servelm - Elm Http Server\n\n# Deprecated. Server side elm is not designed to work this way.\n\n\n\n\nThis server, along with rtfeldman's Elm stylesheets, means that we can now have full stack Elm support. At no point in the development of an application will you have to write anything other than Elm!\n\nIt now supports server-side rendering of elm-html.\n\nA demo can be found [here](http://107.170.81.176/). The styling is done through compile-time correct CSS provided by [elm-stylesheets](https://github.com/rtfeldman/elm-stylesheets).\n\n# APIs exposed\n\nThe Http.Server module allows you to create servers and run them.\n\n## Sending out Elm\n\nUse the `Http.Response.writeElm` function to compile an Elm file on request. It will compile an Elm file found with `name + \".elm\"\"`. It will write the output to a file in the same folder as `name + \".html\"`. This will then be served out to the client. There is basic caching involved at the moment, which works based on the lifecycle of the server. Restart the server if you make any changes.\n\nThis is enabled by the [node-elm-compiler](https://github.com/rtfeldman/node-elm-compiler) package.\n\nIt also supports server-side rendering of elm-html, through using the [vdom-to-html](https://github.com/nthtran/vdom-to-html) package.\n\n\n## Get started\n\nTo start Elm inside of Node simply this to the end of your compiled Elm code.\n\n```JavaScript\nElm.worker(Elm.Main);\n```\n\nTake a look at `example/run.sh` to see a complete usage\n\n```bash\nelm make example/server/Main.elm --output=example/main.js\necho \"Elm.worker(Elm.Main);\" >> example/main.js\nnode example/main.js\n```\n\n## Run the example\n\nThis project depends on Node.js and the `node` command.\n\n```bash\nexample/run.sh\n```\n\nThen load up the browser to see it working!\n\n\n# Credit\n\nOriginally inspired by https://github.com/Fresheyeball/elm-http-server.\n\nThere was some great work already there, I just cleaned it up a little and integrated it with some other packages.\n\n"
  },
  {
    "path": "elm-package.json",
    "content": "{\n    \"version\": \"1.0.0\",\n    \"summary\": \"\",\n    \"repository\": \"https://github.com/eeue56/servelm.git\",\n    \"license\": \"MIT\",\n    \"source-directories\": [\n        \"src/\",\n        \"example/\",\n        \"example/server/\"\n    ],\n    \"exposed-modules\": [\n        \"Http\"\n    ],\n    \"native-modules\": true,\n    \"dependencies\": {\n        \"elm-lang/core\": \"2.1.0 <= v < 3.0.0\",\n        \"evancz/elm-html\": \"4.0.1 <= v < 5.0.0\",\n        \"evancz/virtual-dom\": \"2.1.0 <= v < 3.0.0\"\n    },\n    \"elm-version\": \"0.15.1 <= v < 0.16.0\"\n}\n"
  },
  {
    "path": "example/client/App.elm",
    "content": "module App where\n\nimport Html exposing (..)\nimport Html.Attributes exposing (id, src, href)\nimport HomepageStylesheet exposing (..)\nimport Stylesheets\nimport Json.Encode as Encode\n\n\nmain : Html\nmain =\n    div\n        [ id \"dave\" ]\n        [\n            div [ Html.Attributes.property \"innerHTML\" (Encode.string (\"<style>\" ++ (Stylesheets.prettyPrint 4 HomepageStylesheet.exports) ++ \"</style>\")) ] [],\n\n            div\n                [ ]\n                [ a\n                    [ href \"/App.elm\"\n                    ]\n                    [ text \"This site was entirely written in Elm! Try /App.elm to see the source for this page!\"\n                    ]\n                ]\n        ]\n"
  },
  {
    "path": "example/client/HomepageStylesheet.elm",
    "content": "module HomepageStylesheet where\n\nimport Stylesheets exposing (..)\n\nexports =\n    css\n        |%| body\n            |-| backgroundColor (rgb 173 191 160)\n            |-| boxSizing borderBox\n            |-| padding 12 px\n"
  },
  {
    "path": "example/client/Stylesheets.elm",
    "content": "module Stylesheets where\n\n{-\n    Implementation notes:\n\n    - strip out []()\"\"'' - so:\n    - toString [\"html\", \"body\"] -> \"[\\\"html\\\",\\\"body\\\"]\" -> \"html,body\"\n\n    How would you write this?\n\n    html, body, .foo, .bar\n        width: 100%\n-}\n\nimport String\n\nprettyPrint : Int -> Style class id -> String\nprettyPrint =\n    prettyPrintHelp 0\n\n\nprettyPrintHelp : Int -> Int -> Style class id -> String\nprettyPrintHelp indentLevel indentSpaces (Style selector attributes children) =\n    if (indentLevel == 0) && (String.isEmpty selector) then\n        children\n            |> List.map (prettyPrintHelp indentLevel indentSpaces)\n            |> String.join \"\\n\\n\"\n    else\n        let\n            indentStr =\n                String.repeat (indentSpaces * indentLevel) \" \"\n\n            subIndentStr =\n                indentStr ++ String.repeat (indentSpaces) \" \"\n\n            attrsStr =\n                if List.isEmpty attributes then\n                    \"\"\n                else\n                    attributes\n                        |> List.map attributeToString\n                        |> String.join subIndentStr\n                        |> (++) subIndentStr\n\n            prettyPrintChild =\n                prettyPrintHelp (indentLevel + 1) indentSpaces\n\n            childrenStr =\n                if List.isEmpty children then\n                    \"\"\n                else\n                    children\n                        |> List.map prettyPrintChild\n                        |> String.join subIndentStr\n                        |> (++) subIndentStr\n        in\n            indentStr ++ selector ++ \" {\\n\"\n                ++ attrsStr\n                ++ childrenStr\n                ++ \"}\"\n\n\nattributeToString : Attribute -> String\nattributeToString (Attribute str) =\n    str ++ \";\\n\"\n\n\n{- Tags -}\n\nhtml = Tag \"html\"\nbody = Tag \"body\"\nheader = Tag \"header\"\nnav = Tag \"nav\"\ndiv = Tag \"div\"\nspan = Tag \"span\"\nimg = Tag \"img\"\nnowrap = Tag \"nowrap\"\nbutton = Tag \"button\"\nh1 = Tag \"h1\"\nh2 = Tag \"h2\"\nh3 = Tag \"h3\"\nh4 = Tag \"h4\"\np = Tag \"p\"\nol = Tag \"ol\"\ninput = Tag \"input\"\n\ntagToString (Tag str) = str\n\n\n-- TODO these are just for @media - maybe improve type guarantees?\nscreen = \"screen\"\nprint = \"print\"\n\n-- TODO this is just for ::selection - maybe improve type guarantees?\nselection = \"selection\"\n\n\n{- Units -}\n\ninheritToString : (a -> String) -> InheritOr a -> String\ninheritToString translate value =\n    case value of\n        Inherit ->\n            \"inherit\"\n\n        NotInherit notInherit ->\n            translate notInherit\n\n\nautoToString : (a -> String) -> AutoOr a -> String\nautoToString translate value =\n    case value of\n        Auto ->\n            \"auto\"\n\n        NotAuto notAuto ->\n            translate notAuto\n\nnoneToString : (a -> String) -> NoneOr a -> String\nnoneToString translate value =\n    case value of\n        None ->\n            \"none\"\n\n        NotNone notNone ->\n            translate notNone\n\n\nunitsToString : Units -> String\nunitsToString =\n    (\\(ExplicitUnits str) -> str)\n        |> inheritToString\n\n\nboxSizingToString : BoxSizing -> String\nboxSizingToString =\n    (\\(ExplicitBoxSizing str) -> str)\n        |> inheritToString\n\n\noverflowToString : Overflow -> String\noverflowToString =\n    (\\(ExplicitOverflow str) -> str)\n        |> autoToString\n        |> inheritToString\n\n\ndisplayToString : Display -> String\ndisplayToString =\n    (\\(ExplicitDisplay str) -> str)\n        |> noneToString\n        |> inheritToString\n\n\nverticalAlignToString : VerticalAlign -> String\nverticalAlignToString =\n    (\\(ExplicitVerticalAlign str) -> str)\n        |> inheritToString\n\n\nwhiteSpaceToString : WhiteSpace -> String\nwhiteSpaceToString =\n    (\\(ExplicitWhiteSpace str) -> str)\n        |> autoToString\n        |> inheritToString\n\ncolorToString : Color -> String\ncolorToString =\n    (\\(ExplicitColor str) -> str)\n        |> autoToString\n        |> inheritToString\n\n\nnumberToString : number -> String\nnumberToString num =\n    toString (num + 0)\n\n\ntextShadowToString : TextShadow -> String\ntextShadowToString =\n    explicitTextShadowToString\n        |> noneToString\n        |> inheritToString\n\n\nexplicitTextShadowToString : ExplicitTextShadow -> String\nexplicitTextShadowToString value =\n    case value of\n        NoTextShadow ->\n            \"TODO\"\n\noutlineStyleToString : OutlineStyle -> String\noutlineStyleToString (OutlineStyle str) = str\n\n\nopacityStyleToString : OpacityStyle -> String\nopacityStyleToString (OpacityStyle str) = str\n\n\ntype Tag\n    = Tag String\n\ntype InheritOr a\n    = Inherit\n    | NotInherit a\n\ntype AutoOr a\n    = Auto\n    | NotAuto a\n\ntype NoneOr a\n    = None\n    | NotNone a\n\ntype alias BoxSizing = InheritOr ExplicitBoxSizing\ntype alias Overflow = InheritOr (AutoOr ExplicitOverflow)\ntype alias Display = InheritOr (NoneOr ExplicitDisplay)\ntype alias WhiteSpace = InheritOr (AutoOr ExplicitWhiteSpace)\ntype alias Color = InheritOr (AutoOr ExplicitColor)\ntype alias TextShadow = InheritOr (NoneOr ExplicitTextShadow)\ntype alias Outline = InheritOr ExplicitOutline\ntype alias Units = InheritOr ExplicitUnits\ntype alias VerticalAlign = InheritOr ExplicitVerticalAlign\n\ntype ExplicitUnits = ExplicitUnits String\ntype ExplicitBoxSizing = ExplicitBoxSizing String\ntype ExplicitOverflow = ExplicitOverflow String\ntype ExplicitDisplay = ExplicitDisplay String\ntype ExplicitWhiteSpace = ExplicitWhiteSpace String\ntype ExplicitColor = ExplicitColor String\ntype ExplicitVerticalAlign = ExplicitVerticalAlign String\n\ntype ExplicitOutline\n    = ExplicitOutline Float ExplicitUnits OutlineStyle OpacityStyle\n\ntype OutlineStyle\n    = OutlineStyle String\n\ntype OpacityStyle\n    = OpacityStyle String\n\ntype ExplicitTextShadow\n    = NoTextShadow\n\nsolid : OutlineStyle\nsolid = OutlineStyle \"solid\"\n\ntransparent : OpacityStyle\ntransparent = OpacityStyle \"transparent\"\n\nrgb : number -> number -> number -> Color\nrgb r g b =\n    ExplicitColor (\"rgb(\" ++ (numberToString r) ++ \", \" ++ (numberToString g) ++ \", \" ++ (numberToString b) ++ \")\")\n        |> NotAuto |> NotInherit\n\n\nrgba : number -> number -> number -> number -> Color\nrgba r g b a =\n    ExplicitColor (\"rgba(\" ++ (numberToString r) ++ \", \" ++ (numberToString g) ++ \", \" ++ (numberToString b) ++ \", \" ++ (numberToString a) ++ \")\")\n        |> NotAuto |> NotInherit\n\n\nhex : String -> Color\nhex str =\n    ExplicitColor (\"#\" ++ str)\n        |> NotAuto |> NotInherit\n\npct : Units\npct = \"%\" |> ExplicitUnits |> NotInherit\n\nem : Units\nem = \"em\" |> ExplicitUnits |> NotInherit\n\npx : Units\npx = \"px\" |> ExplicitUnits |> NotInherit\n\nborderBox = \"border-box\" |> ExplicitBoxSizing |> NotInherit\n\nvisible : Display\nvisible = \"visible\" |> ExplicitDisplay |> NotNone |> NotInherit\n\nblock : Display\nblock = \"block\" |> ExplicitDisplay |> NotNone |> NotInherit\n\ninlineBlock : Display\ninlineBlock = \"inline-block\" |> ExplicitDisplay |> NotNone |> NotInherit\n\ninline : Display\ninline = \"inline\" |> ExplicitDisplay |> NotNone |> NotInherit\n\nnone : InheritOr (NoneOr a)\nnone = None |> NotInherit\n\nauto : InheritOr (AutoOr a)\nauto = Auto |> NotInherit\n\ninherit : InheritOr a\ninherit = Inherit\n\nnoWrap : WhiteSpace\nnoWrap = \"no-wrap\" |> ExplicitWhiteSpace |> NotAuto |> NotInherit\n\ntop : VerticalAlign\ntop = \"top\" |> ExplicitVerticalAlign |> NotInherit\n\nmiddle : VerticalAlign\nmiddle = \"middle\" |> ExplicitVerticalAlign |> NotInherit\n\nbottom : VerticalAlign\nbottom = \"bottom\" |> ExplicitVerticalAlign |> NotInherit\n\n\n{- Attributes -}\n\nattr1 name translate value =\n    Attribute (name ++ \": \" ++ (translate value))\n\n\nattr2 name translateA translateB valueA valueB =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB))\n\n\nattr3 name translateA translateB translateC valueA valueB valueC =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB) ++ (translateC valueC))\n\n\nattr4 name translateA translateB translateC translateD valueA valueB valueC valueD =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB) ++ (translateC valueC) ++ (translateD valueD))\n\n\nattr5 name translateA translateB translateC translateD translateE valueA valueB valueC valueD valueE =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB) ++ (translateC valueC) ++ (translateD valueD) ++ (translateE valueE))\n\n\nverticalAlign : VerticalAlign -> Attribute\nverticalAlign =\n    attr1 \"vertical-align\" verticalAlignToString\n\n\ndisplay : Display -> Attribute\ndisplay =\n    attr1 \"display\" displayToString\n\n\nopacity : OpacityStyle -> Attribute\nopacity =\n    attr1 \"opacity\" toString\n\n\nwidth : number -> Units -> Attribute\nwidth =\n    attr2 \"width\" numberToString unitsToString\n\n\nminWidth : number -> Units -> Attribute\nminWidth =\n    attr2 \"min-width\" numberToString unitsToString\n\n\nheight : number -> Units -> Attribute\nheight =\n    attr2 \"height\" numberToString unitsToString\n\n\nminHeight : number -> Units -> Attribute\nminHeight =\n    attr2 \"min-height\" numberToString unitsToString\n\n\npadding : number -> Units -> Attribute\npadding =\n    attr2 \"padding\" numberToString unitsToString\n\npaddingTop : number -> Units -> Attribute\npaddingTop =\n    attr2 \"padding-top\" numberToString unitsToString\n\npaddingBottom : number -> Units -> Attribute\npaddingBottom =\n    attr2 \"padding-bottom\" numberToString unitsToString\n\npaddingRight : number -> Units -> Attribute\npaddingRight =\n    attr2 \"padding-right\" numberToString unitsToString\n\npaddingLeft : number -> Units -> Attribute\npaddingLeft =\n    attr2 \"padding-left\" numberToString unitsToString\n\nmargin : number -> Units -> Attribute\nmargin =\n    attr2 \"margin\" numberToString unitsToString\n\nmarginTop : number -> Units -> Attribute\nmarginTop =\n    attr2 \"margin-top\" numberToString unitsToString\n\nmarginBottom : number -> Units -> Attribute\nmarginBottom =\n    attr2 \"margin-bottom\" numberToString unitsToString\n\nmarginRight : number -> Units -> Attribute\nmarginRight =\n    attr2 \"margin-right\" numberToString unitsToString\n\nmarginLeft : number -> Units -> Attribute\nmarginLeft =\n    attr2 \"margin-left\" numberToString unitsToString\n\nboxSizing : BoxSizing -> Attribute\nboxSizing =\n    attr1 \"box-sizing\" boxSizingToString\n\n\noverflowX : Overflow -> Attribute\noverflowX =\n    attr1 \"overflow-x\" overflowToString\n\n\noverflowY : Overflow -> Attribute\noverflowY =\n    attr1 \"overflow-y\" overflowToString\n\n\nwhiteSpace : WhiteSpace -> Attribute\nwhiteSpace =\n    attr1 \"white-space\" whiteSpaceToString\n\n\n\n\n\nbackgroundColor : Color -> Attribute\nbackgroundColor =\n    attr1 \"background-color\" colorToString\n\n\ncolor : Color -> Attribute\ncolor =\n    attr1 \"color\" colorToString\n\n\nmedia : a -> String\nmedia value =\n    \"media \" ++ (toString value)\n    -- TODO\n\ntextShadow : TextShadow -> Attribute\ntextShadow =\n    attr1 \"text-shadow\" textShadowToString\n\n\noutline : Float -> Units -> OutlineStyle -> OpacityStyle -> Attribute\noutline =\n    attr4\n        \"outline\"\n            toString unitsToString\n            (\\str -> \" \" ++ outlineStyleToString str ++ \" \")\n            opacityStyleToString\n\n\n{- Types -}\n\ntype Style class id\n    = Style String (List Attribute) (List (Style class id))\n\n\ntype Attribute\n    = Attribute String\n\n\ncss : Style class id\ncss =\n    Style \"\" [] []\n\n\nstyleWithPrefix : String -> Style class id -> a -> Style class id\nstyleWithPrefix prefix (Style selector attrs children) childSelector =\n    children ++ [ Style (prefix ++ (toString childSelector)) [] [] ]\n        |> Style selector attrs\n\n\n(|%|) : Style class id -> Tag -> Style class id\n(|%|) (Style selector attrs children) tag =\n    children ++ [ Style (tagToString tag) [] [] ]\n        |> Style selector attrs\n\n\n(|%|=) : Style class id -> List Tag -> Style class id\n(|%|=) (Style selector attrs children) tags =\n    let\n        childSelector =\n            tags\n                |> List.map tagToString\n                |> String.join \", \"\n    in\n        children ++ [ Style childSelector [] [] ]\n            |> Style selector attrs\n\n\n(|@|) : Style class id -> a -> Style class id\n(|@|) = styleWithPrefix \"@\"\n\n\n(|::|) : Style class id -> a -> Style class id\n(|::|) = styleWithPrefix \"::\"\n\n\n(|>%|) : Style class id -> Tag -> Style class id\n(|>%|) (Style selector attrs children) tag =\n    case splitStartLast children of\n        ( _, Nothing ) ->\n            children ++ [ Style (selector ++ \" > \" ++ tagToString tag) [] [] ]\n                |> Style selector attrs\n\n        ( start, Just (Style activeSelector _ _) ) ->\n            children ++ [ Style (activeSelector ++ \" > \" ++ tagToString tag) [] [] ]\n                |> Style selector attrs\n\n\n(|>%|=) : Style class id -> List Tag -> Style class id\n(|>%|=) (Style selector attrs children) tags =\n    let\n        selectorFromTag tag =\n            case splitStartLast children of\n                ( _, Nothing ) ->\n                    selector ++ \" > \" ++ tagToString tag\n\n                ( start, Just (Style activeSelector _ _) ) ->\n                    activeSelector ++ \" > \" ++ tagToString tag\n\n        childSelector =\n            tags\n                |> List.map selectorFromTag\n                |> String.join \", \"\n    in\n        children ++ [ Style childSelector [] [] ]\n            |> Style selector attrs\n\n\n(|.|) : Style class id -> class -> Style class id\n(|.|) = styleWithPrefix \".\"\n\n\n(|#|) : Style class id -> id -> Style class id\n(|#|) = styleWithPrefix \"#\"\n\n\n(|>.|) : Style class id -> a -> Style class id\n(|>.|) = styleWithPrefix \">.\"\n\n\n(|!|) : Style class id -> Attribute -> Style class id\n(|!|) style (Attribute attrString) =\n    transformActiveChild (addAttr (Attribute (attrString ++ \" !important\"))) style\n\n\n(|-|) : Style class id -> Attribute -> Style class id\n(|-|) style attr =\n    transformActiveChild (addAttr attr) style\n\n\naddAttr : Attribute -> Style a b -> Style a b\naddAttr attr (Style selector attrs children) =\n    Style selector (attrs ++ [ attr ]) children\n\n\ntransformActiveChild : (Style a b -> Style a b) -> Style a b -> Style a b\ntransformActiveChild transform (( Style selector attrs children ) as style) =\n    case splitStartLast children of\n        ( _, Nothing ) ->\n            transform style\n\n        ( inactiveChildren, Just activeChild ) ->\n            Style\n                selector\n                attrs\n                (inactiveChildren ++ [ transform activeChild ])\n\n\nsplitStartLast : List a -> (List a, Maybe a)\nsplitStartLast list =\n    case list of\n        [] ->\n            ( [], Nothing )\n\n        elem :: [] ->\n            ( [], Just elem )\n\n        elem :: rest ->\n            let\n                ( start, last ) =\n                    splitStartLast rest\n            in\n                ( elem :: start, last )\n\n"
  },
  {
    "path": "example/client/elm-package.json",
    "content": "{\n    \"version\": \"1.0.0\",\n    \"summary\": \"helpful summary of your project, less than 80 characters\",\n    \"repository\": \"https://github.com/USER/PROJECT.git\",\n    \"license\": \"BSD3\",\n    \"source-directories\": [\n        \".\"\n    ],\n    \"exposed-modules\": [],\n    \"dependencies\": {\n        \"elm-lang/core\": \"2.1.0 <= v < 3.0.0\",\n        \"evancz/elm-html\": \"4.0.1 <= v < 5.0.0\"\n    },\n    \"elm-version\": \"0.15.1 <= v < 0.16.0\"\n}"
  },
  {
    "path": "example/elm-package.json",
    "content": "{\n    \"version\": \"1.0.0\",\n    \"summary\": \"helpful summary of your project, less than 80 characters\",\n    \"repository\": \"https://github.com/USER/PROJECT.git\",\n    \"license\": \"BSD3\",\n    \"source-directories\": [\n        \".\",\n        \"server/\",\n        \"server/Client\"\n    ],\n    \"exposed-modules\": [],\n    \"dependencies\": {\n        \"elm-lang/core\": \"2.1.0 <= v < 3.0.0\",\n        \"evancz/elm-html\": \"4.0.1 <= v < 5.0.0\"\n    },\n    \"elm-version\": \"0.15.1 <= v < 0.16.0\"\n}\n"
  },
  {
    "path": "example/run.sh",
    "content": "elm make example/server/Main.elm --output=example/main.js\necho \"Elm.worker(Elm.Main);\" >> example/main.js\nnode example/main.js\n"
  },
  {
    "path": "example/server/Main.elm",
    "content": "module Main where\n\nimport Http.Server exposing (..)\nimport Http.Request exposing (emptyReq, Request, Method(..))\nimport Http.Response exposing (emptyRes, Response)\nimport Http.Response.Write exposing\n  ( writeHtml, writeJson\n  , writeElm, writeFile\n  , writeNode)\n\nimport Task exposing (..)\nimport Signal exposing (..)\nimport Json.Encode as Json\n\nimport ServerSideClient.App exposing (main)\n\n\nserver : Mailbox (Request, Response)\nserver = mailbox (emptyReq, emptyRes)\n\nroute : (Request, Response) -> Task x ()\nroute (req, res) =\n  case req.method of\n    GET -> case req.url of\n      \"/\" ->\n        writeElm \"/client/App\" res\n      \"/App.elm\" ->\n        writeFile \"/client/App.elm\" res\n      \"/foo\" ->\n        writeHtml \"<h1>Foozle!</h1>\" res\n      \"/bar\" ->\n        writeNode main res\n      url ->\n        writeHtml (\"You tried to go to \" ++ url) res\n\n    POST ->\n      res |>\n        writeJson (Json.object [(\"foo\", Json.string \"bar\")])\n\n    NOOP ->\n      succeed ()\n\n    _ ->\n      res |>\n        writeJson (Json.string \"unknown method!\")\n\nport reply : Signal (Task x ())\nport reply = route <~ dropRepeats server.signal\n\nport serve : Task x Server\nport serve = createServer'\n  server.address\n  8080\n  \"Listening on 8080\"\n"
  },
  {
    "path": "example/server/ServerSideClient/App.elm",
    "content": "module ServerSideClient.App where\n\nimport Html exposing (..)\nimport Html.Attributes exposing (id, src, href)\nimport ServerSideClient.HomepageStylesheet exposing (exports)\nimport ServerSideClient.Stylesheets as Stylesheets\nimport Json.Encode as Encode\n\n\nmain : Html\nmain =\n    div\n        [ id \"dave\" ]\n        [\n            div [ Html.Attributes.property \"innerHTML\" (Encode.string (\"<style>\" ++ (Stylesheets.prettyPrint 4 exports) ++ \"</style>\")) ] [],\n\n            div\n                [ ]\n                [ text \"This page was rendered on the server!\"\n                ]\n        ]\n"
  },
  {
    "path": "example/server/ServerSideClient/HomepageStylesheet.elm",
    "content": "module ServerSideClient.HomepageStylesheet where\n\nimport ServerSideClient.Stylesheets exposing (..)\n\nexports =\n    css\n        |%| body\n            |-| backgroundColor (rgb 173 191 160)\n            |-| boxSizing borderBox\n            |-| padding 12 px\n"
  },
  {
    "path": "example/server/ServerSideClient/Stylesheets.elm",
    "content": "module ServerSideClient.Stylesheets where\n\n{-\n    Implementation notes:\n\n    - strip out []()\"\"'' - so:\n    - toString [\"html\", \"body\"] -> \"[\\\"html\\\",\\\"body\\\"]\" -> \"html,body\"\n\n    How would you write this?\n\n    html, body, .foo, .bar\n        width: 100%\n-}\n\nimport String\n\nprettyPrint : Int -> Style class id -> String\nprettyPrint =\n    prettyPrintHelp 0\n\n\nprettyPrintHelp : Int -> Int -> Style class id -> String\nprettyPrintHelp indentLevel indentSpaces (Style selector attributes children) =\n    if (indentLevel == 0) && (String.isEmpty selector) then\n        children\n            |> List.map (prettyPrintHelp indentLevel indentSpaces)\n            |> String.join \"\\n\\n\"\n    else\n        let\n            indentStr =\n                String.repeat (indentSpaces * indentLevel) \" \"\n\n            subIndentStr =\n                indentStr ++ String.repeat (indentSpaces) \" \"\n\n            attrsStr =\n                if List.isEmpty attributes then\n                    \"\"\n                else\n                    attributes\n                        |> List.map attributeToString\n                        |> String.join subIndentStr\n                        |> (++) subIndentStr\n\n            prettyPrintChild =\n                prettyPrintHelp (indentLevel + 1) indentSpaces\n\n            childrenStr =\n                if List.isEmpty children then\n                    \"\"\n                else\n                    children\n                        |> List.map prettyPrintChild\n                        |> String.join subIndentStr\n                        |> (++) subIndentStr\n        in\n            indentStr ++ selector ++ \" {\\n\"\n                ++ attrsStr\n                ++ childrenStr\n                ++ \"}\"\n\n\nattributeToString : Attribute -> String\nattributeToString (Attribute str) =\n    str ++ \";\\n\"\n\n\n{- Tags -}\n\nhtml = Tag \"html\"\nbody = Tag \"body\"\nheader = Tag \"header\"\nnav = Tag \"nav\"\ndiv = Tag \"div\"\nspan = Tag \"span\"\nimg = Tag \"img\"\nnowrap = Tag \"nowrap\"\nbutton = Tag \"button\"\nh1 = Tag \"h1\"\nh2 = Tag \"h2\"\nh3 = Tag \"h3\"\nh4 = Tag \"h4\"\np = Tag \"p\"\nol = Tag \"ol\"\ninput = Tag \"input\"\n\ntagToString (Tag str) = str\n\n\n-- TODO these are just for @media - maybe improve type guarantees?\nscreen = \"screen\"\nprint = \"print\"\n\n-- TODO this is just for ::selection - maybe improve type guarantees?\nselection = \"selection\"\n\n\n{- Units -}\n\ninheritToString : (a -> String) -> InheritOr a -> String\ninheritToString translate value =\n    case value of\n        Inherit ->\n            \"inherit\"\n\n        NotInherit notInherit ->\n            translate notInherit\n\n\nautoToString : (a -> String) -> AutoOr a -> String\nautoToString translate value =\n    case value of\n        Auto ->\n            \"auto\"\n\n        NotAuto notAuto ->\n            translate notAuto\n\nnoneToString : (a -> String) -> NoneOr a -> String\nnoneToString translate value =\n    case value of\n        None ->\n            \"none\"\n\n        NotNone notNone ->\n            translate notNone\n\n\nunitsToString : Units -> String\nunitsToString =\n    (\\(ExplicitUnits str) -> str)\n        |> inheritToString\n\n\nboxSizingToString : BoxSizing -> String\nboxSizingToString =\n    (\\(ExplicitBoxSizing str) -> str)\n        |> inheritToString\n\n\noverflowToString : Overflow -> String\noverflowToString =\n    (\\(ExplicitOverflow str) -> str)\n        |> autoToString\n        |> inheritToString\n\n\ndisplayToString : Display -> String\ndisplayToString =\n    (\\(ExplicitDisplay str) -> str)\n        |> noneToString\n        |> inheritToString\n\n\nverticalAlignToString : VerticalAlign -> String\nverticalAlignToString =\n    (\\(ExplicitVerticalAlign str) -> str)\n        |> inheritToString\n\n\nwhiteSpaceToString : WhiteSpace -> String\nwhiteSpaceToString =\n    (\\(ExplicitWhiteSpace str) -> str)\n        |> autoToString\n        |> inheritToString\n\ncolorToString : Color -> String\ncolorToString =\n    (\\(ExplicitColor str) -> str)\n        |> autoToString\n        |> inheritToString\n\n\nnumberToString : number -> String\nnumberToString num =\n    toString (num + 0)\n\n\ntextShadowToString : TextShadow -> String\ntextShadowToString =\n    explicitTextShadowToString\n        |> noneToString\n        |> inheritToString\n\n\nexplicitTextShadowToString : ExplicitTextShadow -> String\nexplicitTextShadowToString value =\n    case value of\n        NoTextShadow ->\n            \"TODO\"\n\noutlineStyleToString : OutlineStyle -> String\noutlineStyleToString (OutlineStyle str) = str\n\n\nopacityStyleToString : OpacityStyle -> String\nopacityStyleToString (OpacityStyle str) = str\n\n\ntype Tag\n    = Tag String\n\ntype InheritOr a\n    = Inherit\n    | NotInherit a\n\ntype AutoOr a\n    = Auto\n    | NotAuto a\n\ntype NoneOr a\n    = None\n    | NotNone a\n\ntype alias BoxSizing = InheritOr ExplicitBoxSizing\ntype alias Overflow = InheritOr (AutoOr ExplicitOverflow)\ntype alias Display = InheritOr (NoneOr ExplicitDisplay)\ntype alias WhiteSpace = InheritOr (AutoOr ExplicitWhiteSpace)\ntype alias Color = InheritOr (AutoOr ExplicitColor)\ntype alias TextShadow = InheritOr (NoneOr ExplicitTextShadow)\ntype alias Outline = InheritOr ExplicitOutline\ntype alias Units = InheritOr ExplicitUnits\ntype alias VerticalAlign = InheritOr ExplicitVerticalAlign\n\ntype ExplicitUnits = ExplicitUnits String\ntype ExplicitBoxSizing = ExplicitBoxSizing String\ntype ExplicitOverflow = ExplicitOverflow String\ntype ExplicitDisplay = ExplicitDisplay String\ntype ExplicitWhiteSpace = ExplicitWhiteSpace String\ntype ExplicitColor = ExplicitColor String\ntype ExplicitVerticalAlign = ExplicitVerticalAlign String\n\ntype ExplicitOutline\n    = ExplicitOutline Float ExplicitUnits OutlineStyle OpacityStyle\n\ntype OutlineStyle\n    = OutlineStyle String\n\ntype OpacityStyle\n    = OpacityStyle String\n\ntype ExplicitTextShadow\n    = NoTextShadow\n\nsolid : OutlineStyle\nsolid = OutlineStyle \"solid\"\n\ntransparent : OpacityStyle\ntransparent = OpacityStyle \"transparent\"\n\nrgb : number -> number -> number -> Color\nrgb r g b =\n    ExplicitColor (\"rgb(\" ++ (numberToString r) ++ \", \" ++ (numberToString g) ++ \", \" ++ (numberToString b) ++ \")\")\n        |> NotAuto |> NotInherit\n\n\nrgba : number -> number -> number -> number -> Color\nrgba r g b a =\n    ExplicitColor (\"rgba(\" ++ (numberToString r) ++ \", \" ++ (numberToString g) ++ \", \" ++ (numberToString b) ++ \", \" ++ (numberToString a) ++ \")\")\n        |> NotAuto |> NotInherit\n\n\nhex : String -> Color\nhex str =\n    ExplicitColor (\"#\" ++ str)\n        |> NotAuto |> NotInherit\n\npct : Units\npct = \"%\" |> ExplicitUnits |> NotInherit\n\nem : Units\nem = \"em\" |> ExplicitUnits |> NotInherit\n\npx : Units\npx = \"px\" |> ExplicitUnits |> NotInherit\n\nborderBox = \"border-box\" |> ExplicitBoxSizing |> NotInherit\n\nvisible : Display\nvisible = \"visible\" |> ExplicitDisplay |> NotNone |> NotInherit\n\nblock : Display\nblock = \"block\" |> ExplicitDisplay |> NotNone |> NotInherit\n\ninlineBlock : Display\ninlineBlock = \"inline-block\" |> ExplicitDisplay |> NotNone |> NotInherit\n\ninline : Display\ninline = \"inline\" |> ExplicitDisplay |> NotNone |> NotInherit\n\nnone : InheritOr (NoneOr a)\nnone = None |> NotInherit\n\nauto : InheritOr (AutoOr a)\nauto = Auto |> NotInherit\n\ninherit : InheritOr a\ninherit = Inherit\n\nnoWrap : WhiteSpace\nnoWrap = \"no-wrap\" |> ExplicitWhiteSpace |> NotAuto |> NotInherit\n\ntop : VerticalAlign\ntop = \"top\" |> ExplicitVerticalAlign |> NotInherit\n\nmiddle : VerticalAlign\nmiddle = \"middle\" |> ExplicitVerticalAlign |> NotInherit\n\nbottom : VerticalAlign\nbottom = \"bottom\" |> ExplicitVerticalAlign |> NotInherit\n\n\n{- Attributes -}\n\nattr1 name translate value =\n    Attribute (name ++ \": \" ++ (translate value))\n\n\nattr2 name translateA translateB valueA valueB =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB))\n\n\nattr3 name translateA translateB translateC valueA valueB valueC =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB) ++ (translateC valueC))\n\n\nattr4 name translateA translateB translateC translateD valueA valueB valueC valueD =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB) ++ (translateC valueC) ++ (translateD valueD))\n\n\nattr5 name translateA translateB translateC translateD translateE valueA valueB valueC valueD valueE =\n    Attribute (name ++ \": \" ++ (translateA valueA) ++ (translateB valueB) ++ (translateC valueC) ++ (translateD valueD) ++ (translateE valueE))\n\n\nverticalAlign : VerticalAlign -> Attribute\nverticalAlign =\n    attr1 \"vertical-align\" verticalAlignToString\n\n\ndisplay : Display -> Attribute\ndisplay =\n    attr1 \"display\" displayToString\n\n\nopacity : OpacityStyle -> Attribute\nopacity =\n    attr1 \"opacity\" toString\n\n\nwidth : number -> Units -> Attribute\nwidth =\n    attr2 \"width\" numberToString unitsToString\n\n\nminWidth : number -> Units -> Attribute\nminWidth =\n    attr2 \"min-width\" numberToString unitsToString\n\n\nheight : number -> Units -> Attribute\nheight =\n    attr2 \"height\" numberToString unitsToString\n\n\nminHeight : number -> Units -> Attribute\nminHeight =\n    attr2 \"min-height\" numberToString unitsToString\n\n\npadding : number -> Units -> Attribute\npadding =\n    attr2 \"padding\" numberToString unitsToString\n\npaddingTop : number -> Units -> Attribute\npaddingTop =\n    attr2 \"padding-top\" numberToString unitsToString\n\npaddingBottom : number -> Units -> Attribute\npaddingBottom =\n    attr2 \"padding-bottom\" numberToString unitsToString\n\npaddingRight : number -> Units -> Attribute\npaddingRight =\n    attr2 \"padding-right\" numberToString unitsToString\n\npaddingLeft : number -> Units -> Attribute\npaddingLeft =\n    attr2 \"padding-left\" numberToString unitsToString\n\nmargin : number -> Units -> Attribute\nmargin =\n    attr2 \"margin\" numberToString unitsToString\n\nmarginTop : number -> Units -> Attribute\nmarginTop =\n    attr2 \"margin-top\" numberToString unitsToString\n\nmarginBottom : number -> Units -> Attribute\nmarginBottom =\n    attr2 \"margin-bottom\" numberToString unitsToString\n\nmarginRight : number -> Units -> Attribute\nmarginRight =\n    attr2 \"margin-right\" numberToString unitsToString\n\nmarginLeft : number -> Units -> Attribute\nmarginLeft =\n    attr2 \"margin-left\" numberToString unitsToString\n\nboxSizing : BoxSizing -> Attribute\nboxSizing =\n    attr1 \"box-sizing\" boxSizingToString\n\n\noverflowX : Overflow -> Attribute\noverflowX =\n    attr1 \"overflow-x\" overflowToString\n\n\noverflowY : Overflow -> Attribute\noverflowY =\n    attr1 \"overflow-y\" overflowToString\n\n\nwhiteSpace : WhiteSpace -> Attribute\nwhiteSpace =\n    attr1 \"white-space\" whiteSpaceToString\n\n\n\n\n\nbackgroundColor : Color -> Attribute\nbackgroundColor =\n    attr1 \"background-color\" colorToString\n\n\ncolor : Color -> Attribute\ncolor =\n    attr1 \"color\" colorToString\n\n\nmedia : a -> String\nmedia value =\n    \"media \" ++ (toString value)\n    -- TODO\n\ntextShadow : TextShadow -> Attribute\ntextShadow =\n    attr1 \"text-shadow\" textShadowToString\n\n\noutline : Float -> Units -> OutlineStyle -> OpacityStyle -> Attribute\noutline =\n    attr4\n        \"outline\"\n            toString unitsToString\n            (\\str -> \" \" ++ outlineStyleToString str ++ \" \")\n            opacityStyleToString\n\n\n{- Types -}\n\ntype Style class id\n    = Style String (List Attribute) (List (Style class id))\n\n\ntype Attribute\n    = Attribute String\n\n\ncss : Style class id\ncss =\n    Style \"\" [] []\n\n\nstyleWithPrefix : String -> Style class id -> a -> Style class id\nstyleWithPrefix prefix (Style selector attrs children) childSelector =\n    children ++ [ Style (prefix ++ (toString childSelector)) [] [] ]\n        |> Style selector attrs\n\n\n(|%|) : Style class id -> Tag -> Style class id\n(|%|) (Style selector attrs children) tag =\n    children ++ [ Style (tagToString tag) [] [] ]\n        |> Style selector attrs\n\n\n(|%|=) : Style class id -> List Tag -> Style class id\n(|%|=) (Style selector attrs children) tags =\n    let\n        childSelector =\n            tags\n                |> List.map tagToString\n                |> String.join \", \"\n    in\n        children ++ [ Style childSelector [] [] ]\n            |> Style selector attrs\n\n\n(|@|) : Style class id -> a -> Style class id\n(|@|) = styleWithPrefix \"@\"\n\n\n(|::|) : Style class id -> a -> Style class id\n(|::|) = styleWithPrefix \"::\"\n\n\n(|>%|) : Style class id -> Tag -> Style class id\n(|>%|) (Style selector attrs children) tag =\n    case splitStartLast children of\n        ( _, Nothing ) ->\n            children ++ [ Style (selector ++ \" > \" ++ tagToString tag) [] [] ]\n                |> Style selector attrs\n\n        ( start, Just (Style activeSelector _ _) ) ->\n            children ++ [ Style (activeSelector ++ \" > \" ++ tagToString tag) [] [] ]\n                |> Style selector attrs\n\n\n(|>%|=) : Style class id -> List Tag -> Style class id\n(|>%|=) (Style selector attrs children) tags =\n    let\n        selectorFromTag tag =\n            case splitStartLast children of\n                ( _, Nothing ) ->\n                    selector ++ \" > \" ++ tagToString tag\n\n                ( start, Just (Style activeSelector _ _) ) ->\n                    activeSelector ++ \" > \" ++ tagToString tag\n\n        childSelector =\n            tags\n                |> List.map selectorFromTag\n                |> String.join \", \"\n    in\n        children ++ [ Style childSelector [] [] ]\n            |> Style selector attrs\n\n\n(|.|) : Style class id -> class -> Style class id\n(|.|) = styleWithPrefix \".\"\n\n\n(|#|) : Style class id -> id -> Style class id\n(|#|) = styleWithPrefix \"#\"\n\n\n(|>.|) : Style class id -> a -> Style class id\n(|>.|) = styleWithPrefix \">.\"\n\n\n(|!|) : Style class id -> Attribute -> Style class id\n(|!|) style (Attribute attrString) =\n    transformActiveChild (addAttr (Attribute (attrString ++ \" !important\"))) style\n\n\n(|-|) : Style class id -> Attribute -> Style class id\n(|-|) style attr =\n    transformActiveChild (addAttr attr) style\n\n\naddAttr : Attribute -> Style a b -> Style a b\naddAttr attr (Style selector attrs children) =\n    Style selector (attrs ++ [ attr ]) children\n\n\ntransformActiveChild : (Style a b -> Style a b) -> Style a b -> Style a b\ntransformActiveChild transform (( Style selector attrs children ) as style) =\n    case splitStartLast children of\n        ( _, Nothing ) ->\n            transform style\n\n        ( inactiveChildren, Just activeChild ) ->\n            Style\n                selector\n                attrs\n                (inactiveChildren ++ [ transform activeChild ])\n\n\nsplitStartLast : List a -> (List a, Maybe a)\nsplitStartLast list =\n    case list of\n        [] ->\n            ( [], Nothing )\n\n        elem :: [] ->\n            ( [], Just elem )\n\n        elem :: rest ->\n            let\n                ( start, last ) =\n                    splitStartLast rest\n            in\n                ( elem :: start, last )\n\n"
  },
  {
    "path": "src/Http/Listeners.elm",
    "content": "module Http.Listeners (on) where\n{-| Module for event listener helpers\n\n@docs on\n-}\n\nimport Native.Http\n\n{-| Wrapper for creating even listeners\n-}\non : String -> target -> Signal input\non = Native.Http.on\n"
  },
  {
    "path": "src/Http/Request.elm",
    "content": "module Http.Request\n  ( Method(..)\n  , Request, emptyReq\n  , onCloseReq\n  ) where\n\n{-| Stuff for dealing with requests\n# Handle Requests\n@docs Request, emptyReq\n\n@docs Method\n\n# Events\n\n@docs onCloseReq\n-}\n\nimport Http.Listeners exposing (on)\n\n{-| Standard Http Methods, useful for routing -}\ntype Method\n  = GET\n  | POST\n  | PUT\n  | DELETE\n  | NOOP\n\n\n{-| Node.js native Request object\n[Node Docs](https://nodejs.org/api/http.html#http_http_incomingmessage) -}\ntype alias Request =\n  { url : String\n  , method : Method }\n\n\n{-| `emptyReq` is a dummy Native Request object incase you need it, as the initial value of\na `Signal.Mailbox` for example. -}\nemptyReq : Request\nemptyReq =\n  { url = \"\"\n  , method = NOOP }\n\n\n{-| \"Close\" events as a Signal for Request objects.\n[Node docs](https://nodejs.org/api/http.html#http_event_close_2) -}\nonCloseReq : Request -> Signal ()\nonCloseReq = on \"close\"\n\n\n"
  },
  {
    "path": "src/Http/Response/Write.elm",
    "content": "module Http.Response.Write\n  ( write, writeHead\n  , writeHtml, writeJson\n  , writeFile, writeElm\n  , writeNode\n  , end) where\n\n\nimport Native.Http.Response.Write\nimport Task exposing (Task, andThen)\nimport VirtualDom exposing (Node)\nimport Json.Encode as Json\nimport Http.Response exposing (textHtml, applicationJson, Header, Response, StatusCode)\n\n{-| Write Headers to a Response\n[Node Docs](https://nodejs.org/api/http.html#http_response_writehead_statuscode_statusmessage_headers) -}\nwriteHead : StatusCode -> Header -> Response -> Task x Response\nwriteHead = Native.Http.Response.Write.writeHead\n\n{-| Write body to a Response\n[Node Docs](https://nodejs.org/api/http.html#http_response_write_chunk_encoding_callback) -}\nwrite : String -> Response -> Task x Response\nwrite = Native.Http.Response.Write.write\n\n{-| End a Response\n[Node Docs](https://nodejs.org/api/http.html#http_response_end_data_encoding_callback) -}\nend : Response -> Task x ()\nend = Native.Http.Response.Write.end\n\nwriteAs : Header -> String -> Response -> Task x ()\nwriteAs header html res =\n  writeHead 200 header res\n  `andThen` write html `andThen` end\n\n{-| Write out HTML to a Response. For example\n\n    res `writeHtml` \"<h1>Howdy</h1>\"\n\n -}\nwriteHtml : String -> Response -> Task x ()\nwriteHtml = writeAs textHtml\n\n{-| Write out JSON to a Response. For example\n    res `writeJson` Json.object\n      [ (\"foo\", Json.string \"bar\")\n      , (\"baz\", Json.int 0) ]\n-}\nwriteJson : Json.Value -> Response -> Task x ()\nwriteJson val res =\n  writeAs applicationJson (Json.encode 0 val) res\n\n{-| write a file -}\nwriteFile : String -> Response -> Task a ()\nwriteFile file res =\n  writeHead 200 textHtml res\n    `andThen` Native.Http.Response.Write.writeFile file\n    `andThen` end\n\n{-| write elm! -}\nwriteElm : String -> Response -> Task a ()\nwriteElm file res =\n  writeHead 200 textHtml res\n    `andThen` Native.Http.Response.Write.writeElm file\n    `andThen` end\n\nwriteNode : Node -> Response -> Task a ()\nwriteNode node res =\n  writeHead 200 textHtml res\n    `andThen` Native.Http.Response.Write.writeNode node\n    `andThen` end\n"
  },
  {
    "path": "src/Http/Response.elm",
    "content": "module Http.Response\n  ( Response, StatusCode, Header\n  , emptyRes\n  , textHtml, applicationJson\n  , onCloseRes, onFinishRes\n  ) where\n\nimport Http.Listeners exposing (on)\n\n\n{-| An http header, such as content type -}\ntype alias Header = (String, String)\n\n{-| StatusCode ie 200 or 404 -}\ntype alias StatusCode = Int\n\n{-| Node.js native Response object\n[Node Docs](https://nodejs.org/api/http.html#http_class_http_serverresponse) -}\ntype alias Response =\n  { statusCode : StatusCode }\n\n{-| `emptyRes` is a dummy Native Response object incase you need it, as the initial value of\na `Signal.Mailbox` for example. -}\nemptyRes : Response\nemptyRes =\n  { statusCode = 418 }\n\n{-| Html Header {\"Content-Type\":\"text/html\"}-}\ntextHtml : Header\ntextHtml = (\"Content-Type\", \"text/html\")\n\n{-| Json Header {\"Content-Type\":\"application/json\"}-}\napplicationJson : Header\napplicationJson = (\"Content-Type\", \"application/json\")\n\n\n{-| \"Close\" events as a Signal for Response objects.\n[Node docs](https://nodejs.org/api/http.html#http_event_close_1) -}\nonCloseRes : Response -> Signal ()\nonCloseRes = on \"close\"\n\n{-| \"Finsh\" events as a Signal for Response objects.\n[Node docs](https://nodejs.org/api/http.html#http_event_finish) -}\nonFinishRes : Response -> Signal ()\nonFinishRes = on \"finish\"\n"
  },
  {
    "path": "src/Http/Server.elm",
    "content": "module Http.Server\n  ( createServer, createServer', listen\n  , Port, Server\n  , onRequest, onClose) where\n\n{-| Simple bindings to Node.js's Http.Server\n\n# Init the server\n\n## Instaniation\n@docs createServer, createServer'\n\n## Actually listen\n@docs listen\n\n## Types\n@docs Server, Port\n\n# Listen for events\n@docs onRequest, onClose\n-}\n\nimport Task exposing (Task, succeed, andThen)\nimport Signal exposing (Address, Mailbox, mailbox)\nimport Json.Encode as Json\n\nimport Http.Request exposing (Request)\nimport Http.Response exposing (Response)\nimport Http.Listeners exposing (on)\n\nimport Native.Http\n\n{-| Port number for the server to listen -}\ntype alias Port = Int\n\n\n{-| Node.js native Server object\n[Node Docs](https://nodejs.org/api/http.html#http_class_http_server) -}\ntype Server = Server\n\n{-| \"Request\" events as a Signal.\n[Node docs](https://nodejs.org/api/http.html#http_event_request) -}\nonRequest : Server -> Signal (Request, Response)\nonRequest = on \"request\"\n\n{-| \"Close\" events as a Signal for Servers.\n[Node docs](https://nodejs.org/api/http.html#http_event_close) -}\nonClose : Server -> Signal ()\nonClose = on \"close\"\n\n\n{-| Create a new Http Server, and send (Request, Response) to an Address. For example\n\n    port serve : Task x Server\n    port serve = createServer server.address\n\n[Node docs](https://nodejs.org/api/http.html#http_http_createserver_requestlistener)\n-}\ncreateServer : Address (Request, Response) -> Task x Server\ncreateServer = Native.Http.createServer\n\n{-| Create a Http Server and listen in one command! For example\n    port serve : Task x Server\n    port serve = createServer' server.address 8080 \"Alive on 8080!\"\n-}\n\ncreateServer' : Address (Request, Response) -> Port -> String -> Task x Server\ncreateServer' address port' text  =\n  createServer address `andThen` listen port' text\n\n{-| Command Server to listen on a specific port,\n    and echo a message to the console when active.\n    Task will not resolve until listening is successful.\n    For example\n\n    port listen : Task x Server\n    port listen = listen 8080 \"Listening on 8080\" server\n\n[Node Docs](https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback)\n-}\nlisten : Port -> String -> Server -> Task x Server\nlisten = Native.Http.listen\n"
  },
  {
    "path": "src/Native/Http/Response/Write.js",
    "content": "var COMPILED_DIR = '.comp';\n\nvar writeHead = function writeHead(Task) {\n    return function (code, header, res) {\n        var o = {};\n        return Task.asyncFunction(function (callback) {\n            o[header._0] = header._1;\n            res.writeHead(code, o);\n            return callback(Task.succeed(res));\n        });\n    };\n};\n\nvar write = function write(Task) {\n    return function (message, res) {\n        return Task.asyncFunction(function (callback) {\n            res.write(message);\n            return callback(Task.succeed(res));\n        });\n    };\n};\n\nvar writeFile = function writeFile(fs, mime, Task){\n    return function (fileName, res) {\n        return Task.asyncFunction(function (callback) {\n            var file = __dirname + fileName;\n            var type = mime.lookup(file);\n\n            res.writeHead('Content-Type', type);\n\n            fs.readFile(file, function (e, data) {\n                res.end(data);\n                return callback(Task.succeed(res));\n            });\n\n        });\n    };\n};\n\nvar compile\n\nvar writeElm = function writeElm(fs, mime, crypto, compiler, Task){\n\n    var compile = function(file, outFile, onClose){\n        // switch to the directory that the elm-app is served out of\n\n        var dirIndex = file.lastIndexOf('/');\n        var dir = file.substr(0, dirIndex);\n        process.chdir(dir);\n\n        compiler.compile([file + '.elm'], {\n            output: outFile,\n            yes: true\n        }).on('close', onClose);\n    }\n\n    return function (fileName, res) {\n        var compiledFile = COMPILED_DIR + fileName + '.html';\n\n        // if the file is already compiled, just send it out\n        if (fs.existsSync(compiledFile)) {\n            return writeFile(fs, mime, Task)(\"/\" + compiledFile, res);\n        }\n\n        return Task.asyncFunction(function (callback) {\n            var file = __dirname + fileName;\n            var outFile = __dirname + \"/\" + compiledFile;\n\n            // when the file is compiled, attempt to send it out\n            var onClose = function(exitCode) {\n                var type = mime.lookup(file + '.html');\n                res.writeHead('Content-Type', type);\n\n                fs.readFile(outFile, function (e, data) {\n                    res.end(data);\n                    return callback(Task.succeed(res));\n                });\n            };\n\n            compile(file, outFile, onClose);\n        });\n    };\n};\n\nvar writeNode = function writeNode(toHtml, Task){\n    return function(node, res) {\n        return write(Task)(toHtml(node), res);\n    };\n};\n\nvar end = function end(Task, Tuple0) {\n    return function (res) {\n        return Task.asyncFunction(function (callback) {\n            return (function () {\n                res.end();\n                return callback(Task.succeed(Tuple0));\n            })();\n        });\n    };\n};\n\nvar make = function make(localRuntime) {\n    localRuntime.Native = localRuntime.Native || {};\n    localRuntime.Native.Http = localRuntime.Native.Http || {};\n    localRuntime.Native.Http.Response = localRuntime.Native.Http.Response || {};\n    localRuntime.Native.Http.Response.Write = localRuntime.Native.Http.Response.Write || {};\n\n    if (localRuntime.Native.Http.Response.Write.values) {\n        return localRuntime.Native.Http.Response.Write.values;\n    }\n\n    var fs = require('fs');\n    var crypto = require('crypto');\n\n    var mime = require('mime');\n    var compiler = require('node-elm-compiler');\n    var toHtml = require('vdom-to-html');\n\n    var Task = Elm.Native.Task.make(localRuntime);\n    var Utils = Elm.Native.Utils.make(localRuntime);\n    var Tuple0 = Utils['Tuple0'];\n\n\n    return {\n        'writeHead': F3(writeHead(Task)),\n        'writeFile': F2(writeFile(fs, mime, Task)),\n        'writeElm': F2(writeElm(fs, mime, crypto, compiler, Task)),\n        'writeNode': F2(writeNode(toHtml, Task)),\n        'write': F2(write(Task)),\n        'toHtml': toHtml,\n        'end': end(Task, Tuple0)\n    };\n};\n\nElm.Native = Elm.Native || {};\nElm.Native.Http = Elm.Native.Http || {};\nElm.Native.Http.Response = Elm.Native.Http.Response || {};\nElm.Native.Http.Response.Write = Elm.Native.Http.Response.Write || {};\nElm.Native.Http.Response.Write.make = make;\n\nif (typeof window === \"undefined\") {\n    window = global;\n}\n"
  },
  {
    "path": "src/Native/Http.js",
    "content": "var COMPILED_DIR = '.comp';\n\n// take a name as a string, return an elm object of the type\n// the name given\nvar wrap_with_type = function(item){\n    return {\n        ctor: item\n    };\n};\n\n// make the directory for compiled Elm code\nvar make_compile_dir = function(fs, dir){\n    if (typeof dir === \"undefined\"){\n        dir = COMPILED_DIR;\n    }\n\n    if (!fs.existsSync(dir)){\n       fs.mkdirSync(dir);\n    }\n};\n\nvar createServer = function createServer(fs, http, Tuple2, Task) {\n    return function (address) {\n        make_compile_dir(fs, __dirname + \"/\" + COMPILED_DIR);\n\n        var send = address._0;\n        var server = http.createServer(function (request, response) {\n            request.method = wrap_with_type(request.method);\n            return Task.perform(send(Tuple2(request, response)));\n        });\n        return Task.asyncFunction(function (callback) {\n            return callback(Task.succeed(server));\n        });\n    };\n};\n\nvar listen = function listen(Task) {\n    return function (port, echo, server) {\n        return Task.asyncFunction(function (callback) {\n            return server.listen(port, function () {\n                console.log(echo);\n                return callback(Task.succeed(server));\n            });\n        });\n    };\n};\n\nvar on = function on(Signal) {\n    return function (eventName, x) {\n        return x.on(eventName, function (request, response) {\n            if (typeof(request) == 'undefined') {\n                return Signal.input(eventName, Tuple0);\n            }\n            return Signal.input(eventName, Tuple(request, response));\n        });\n    };\n};\nvar make = function make(localRuntime) {\n    localRuntime.Native = localRuntime.Native || {};\n    localRuntime.Native.Http = localRuntime.Native.Http || {};\n\n\n    if (localRuntime.Native.Http.values) {\n        return localRuntime.Native.Http.values;\n    }\n\n    var http = require('http');\n    var fs = require('fs');\n    var mime = require('mime');\n\n    var Task = Elm.Native.Task.make(localRuntime);\n    var Utils = Elm.Native.Utils.make(localRuntime);\n    var Signal = Elm.Native.Signal.make(localRuntime);\n    var Tuple0 = Utils['Tuple0'];\n    var Tuple2 = Utils['Tuple2'];\n\n    return {\n        'createServer': createServer(fs, http, Tuple2, Task),\n        'listen': F3(listen(Task)),\n        'on': F2(on(Signal, Tuple0))\n    };\n};\nElm.Native.Http = {};\nElm.Native.Http.make = make;\n\nif (typeof window === \"undefined\") {\n    window = global;\n}\n"
  }
]