deprecated-elm-http-server
deprecated-elm-http-server copied to clipboard
Elm server-side
DEPRECIATED
Check out servelm instead, which uses this project as a basis for providing a server side framework for Elm.
Elm Http Server
This 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!
A demo can be found here. The styling is done through compile-time correct CSS provided by elm-stylesheets.
APIs exposed
The Http.Server module allows you to create servers and run them.
Sending out Elm
Use 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 no caching involved, meaning that every request that involves a call to writeElm will trigger a compile. Use this function as a proof of concept.
This is enabled by the node-elm-compiler package.
Get started
To start Elm inside of Node simply this to the end of your compiled Elm code.
Elm.worker(Elm.Main);
Take a look at example/run.sh to see a complete usage
elm make example/server/Main.elm --output=example/main.js
echo "Elm.worker(Elm.Main);" >> example/main.js
node example/main.js
Run the example
This project depends on Node.js and the node command.
example/run.sh
Then load up the browser to see it working!
Credit
Originally inspired by https://github.com/Fresheyeball/elm-http-server.
This is now substantially different from the original.