Minimal functor to turn awful websites into standalone programs: Top-level Files of tip

Files in the top-level directory from the latest check-in


awful-main

Description

This module allows you to quickly turn your awful web applications into static executables.

Author

Pietro Cerutti

Repository

https://code.ptrcrt.ch/awful-main

Requirements

API

Instantiation

This module exposes a single functor, awful main, which is instantiated to produce a main module that can be compiled into a static executable.

This can be done using two separate modules:

; site.scm
(module site (run)
  (import scheme awful (chicken base) (chicken format))
  (define (run args)
    (let ((name (member "name" args)))
      (unless name (error "Required argument: name"))
      (define-page
        (main-page-path)
        (lambda ()
          (set-page-title! "awful-main example")
          (sprintf "Hi, ~A, I'm using awful-main" (cadr name)))))))
; main.scm
(import (awful main) site)
(module main = ((awful main) site))

... or with a single in-line functor instantiation:

; main.scm
(import (awful main))
(module main = (awful main)
  (import scheme awful (chicken base) (chicken format))
  (define (run args)
    (let ((name (member "name" args)))
      (unless name (error "Required argument: name"))
      (define-page
        (main-page-path)
        (lambda ()
          (set-page-title! "awful-main example")
          (sprintf "Hi, ~A, I'm using awful-main" (cadr name)))))))

A static executable implementing the website can then be compiled, e.g., via the command line csm -static -program main.

Runtime

The generated main program can be invoked with the following arguments, where <root> is the directory containing the main program.

-user       user          User to run the website as
-addr       <ip-addr>     Bind to <ip-addr>                   default: 127.0.0.1
-port       <port-num>    Bind to <port-num>                  default: 8080
-access-log <path>        Enable access log to <path>         default: <root>/access.log
-debug-log  <path>        Enable debug log to <path>          default: disabled
-error-log  <path>        Enable error log to <path>          default: <root>/error.log
-web-root   <path>        Path to the web-root                default: <root>/static
-dev                      Start awful in dev mode             default: false
-args                     Pass additional arguments to `run`

If -args is specified, any additional arguments present on the command line are passed to the run function in the implementation. Example:

./main --port=9092 --web-root=./static --args name Joe

For a minimal working example, see the example directory in the source code repository.

License

Copyright (c) Pietro Cerutti
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

Version History