REBOL [
Title: "Micro Web Server"
Date: 24-June-1999
Purpose: "A web server for HTML and images only"
]
web-dir: %web-pages
listen-port: open/lines tcp://:80 ; port used for web connections
errors: [
400 "Forbidden" "No permission to access:"
404 "Not Found" "File was not found:"
]
send-error: function [err-num file] [err] [
err: find errors err-num
insert http-port form ["HTTP/1.0"
err-num err/2 "^/Content-type: text/html^/^/"
<HTML> <TITLE> err/2 </TITLE>
"<BODY><H1>SERVER ERROR</H1><P>REBOL Webserver Error:"
err/3 file newline <P> </BODY> </HTML>
]
]
send-page: func [data mime] [
insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
write-io http-port data length? data
]
while [on] [
http-port: first wait listen-port
request: first http-port
file: "index.html"
mime: "text/plain"
parse request ["get" ["http" | "/ " | copy file to " "]]
parse file [thru "." [
"html" (mime: "text/html") |
"gif" (mime: "image/gif") |
"jpg" (mime: "image/jpeg")
]
]
]
any [
if not exists? web-dir/:file [send-error 404 file]
if error? try [data: read/binary web-dir/:file] [send-error 400 file]
send-page data mime
]
close http-port
]
Script Junkie | REBOL Bots
Over the past two decades, my search for the perfect scripting language led me to work with companies such as HP, Amiga, and Apple. In that time, I investigated more than 50 different languages, from Ada to C, from Pascal to Lisp. I wanted a language that was very simple and readable with almost no syntax, yet very flexible with a wide degree of expressive freedom.Related Reading
More Insights
| To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |
Best of the Web
First C Compiler Now on Github
The earliest known C compiler by the legendary Dennis Ritchie has been published on the repository.
HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)
HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)
Building Bare Metal ARM Systems with GNU
All you need to know to get up and running... and programming on ARM
Amazon's Vogels Challenges IT: Rethink App Dev
Amazon Web Services CTO says promised land of cloud computing requires a new generation of applications that follow different principles.
How to Select a PaaS Partner
Eventually, the vast majority of Web applications will run on a platform-as-a-service, or PaaS, vendor's infrastructure. To help sort out the options, we sent out a matrix with more than 70 decision points to a variety of PaaS providers.

