Paste: very, very, very basic webserver

Author: ben_m
Mode: factor
Date: Fri, 19 Feb 2010 03:52:54
Plain Text |
! Copyright (C) 2010 Benjamin Meinl.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors io io.encodings.utf8 io.servers.connection multiline
threads ;
IN: simple-webserver

CONSTANT: port 8080
CONSTANT: host "localhost"

STRING: static-site
HTTP/1.1 200 OK

<html>
  <head>
    <title>Mojolicious, baby!</title>
  </head>
  <body>
    <h1>Hi there</h1>
  </body>
</html>
;

: handle-request ( -- )
    static-site print ;

: <webserver> ( -- threaded-server )
    utf8 <threaded-server>
        "time-server" >>name
        port >>insecure
        [ handle-request ] >>handler ;

: start-webserver ( -- threaded-server )
    <webserver> [ start-server ] in-thread ;

: stop-webserver ( threaded-server -- )
    stop-server ;

New Annotation

Summary:
Author:
Mode:
Body: