Giter Club home page Giter Club logo

livefire's Introduction

Live Coding with Livefire

Livefire is a minimalist HTTP Server for live coding applications. It serves a number of local files on the command line and constructs skeleton HTML page around them that will automatically refresh when any of the files change according to the operating system.

Installation:

Livefire depends on Go 1.0 or later, Tarantula and FsNotify. If you already have go installed, installing Livefire should be as simple as:

go get github.com/swdunlop/livefire

Usage:

Livefire serves a number of local files on the command line and constructs skeleton HTML page around them that will automatically refresh when any of the files change according to the operating system. The composition of this file depends on the extension of the files.

livefire option ... path ...
  -bind="127.0.0.1:8080": where the http server should listen
  -title="Livefire Exercise": title for the generated html page
  -fwd="": URL for a subordinate server for any unrecognized paths

File Handling:
  .css: wrapped with a <style> tag and placed in the <head>
  .html: placed verbatim in the <body>
  .js: wrapped with a <script> tag and placed in the <head>
  .*: served as a file with an autodetected MIME type

Example:

Go to Bootstrap and fetch their CSS and other materials into a working directory. Create two new files, scratch.js and body.html and run livefire * in that directory. Point your browser at http://127.0.0.1:8080/ and point your text editor at body.html. Insert the following text:

<h3>Hello, Livefire!</h3>

And save. Your browser should automatically refresh to show you the changed data.

How Does it Work?

Livefire uses FsNotify to track all of the specified files in a goroutine. When your browser contacts the server, Livefire assembles a simple skeleton integrating all of these files it recognizes along with a shim that watches /.watch?t=$now, which will block until FsNotify notices a change. When /.watch returns, the browser will automatically refresh the page, picking up your changes.

For files that Livefire doesn't understand, like PNGs, it will just forward the file whenever it is requested. If you update the file, that will trigger a refresh as well -- handy for you graphical types.

If Livefire doesn't know what to do with a URL, but it was given a -fwd option, it will forward the request, acting as a reverse proxy. This makes hacking on experimental interfaces in front of a production API easier, and was its original use case.

But I wanted to save state / code in the browser / hax0r the gibson!

Well, I'm happy to accept pull requests. This was the stupidest thing that would let me hack on processing.js that I could accept.

What the hell was this written for?

Between me, and my data at ThreatGRID, there is a lot of Java. Nobody in their right mind would want me in their Web Application Server, so I prefer to shove my experiments over the top.

livefire's People

Contributors

swdunlop avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.