Giter VIP home page Giter VIP logo

bashtron's Introduction

Attention: this README is not up to date, a new one is being worked on.

In the mean time, please see https://github.com/redrock9/bashlord.com as an example project that works with the the latest version of bashtron.

bashtron - a web framework for bash

Bashtron is a web framework for the bash programming language. It leverages the nodejs http library to host bash scripts that function as controllers and generate html.

How does it work?

The ServerGenerator script in the root of the project generates javascript code for the nodejs runtime. The generated code will run a server that listens on the port that is defined in the port variable in the current shell. You can add routes to the server by appending the route command.

Dependencies

Except for depending on nodejs, bashtron is written in pure bash and the generated javascript exclusively uses the native nodejs libraries. So no node_modules with the weight of ten cities for this framework!

Examples

You can see this framework in action at bashlord.com (GitHub link)

Creating a server that routes all requests to a script

    source $BASH_LIB/bashtron/ServerGenerator.bash 

{ 
    port=3000 # Define the port that the server should listen on.

    ##
    # Generate javascript code.
    # The --default option tells the bashtron where to route any undefined routes to.
    # The --execute flag tells bashtron which script to execute
    # The --get-params option tells bashtron to append the GET parameters of the request
    # to the parameters of your script in the form [-g [ param_name ] [ param_value ]]
    # a request to /?hi=bye would result in the parameters -g hi bye for example.

    server route --default --execute SomeScript.bash --get-params

} | node # Pipe into node for execution

More advanced routing

source $BASH_LIB/bashtron/ServerGenerator.bash

{
    port=3000
  
    ##
    # The --default flag tells bashtron what page to use for non defined routes.
    # The --execute flag tells bashtron what script to execute for this route.
    # When not using the --default flag, the first argument after `route` is used
    # as the url path. So route somewhere will result in a route for /somewhere.
    # The --split-routes splits the remainder of the url string into command line arguments
    # at every forward slash, so /somewhere/else/route will result in the execution of 
    # SubRouter.bash with the arguments else route (else is $1, route is $2)
    # the last route tells bashtron to serve the files in the dir 'public' at the
    # url path '/public'
    server\ 
      route --default --execute Index.bash\
      route somewhere --execute SubRouter.bash --split-routes\
      route public --static public
} | node 

bashtron's People

Contributors

hugot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.