aardvark.code
 
10_static_ws
20161015

Simple static webserver

What?

It's always handy to have the code of a simple static webserver lying about. This one is in Go, and serves some literature!

Prerequisite

To run this aardvark.code example you need to have following software installed on your system:

Go aardvark

Grab this aardvark.code file:

wget http://data.munging.ninja/aardvarkcode/staticws/aardvark.code

Execute

Output of the run :

aardvark

Extract from Project Gutenberg EBook of War and Peace, by Leo Tolstoy

Not only the generals in full parade uniforms, with their thin or 
thick waists drawn in to the utmost, their red necks squeezed into 
their stiff collars, and wearing scarves and all their decorations, 
not only the elegant, pomaded officers, but every soldier with his 
freshly washed and shaven face and his weapons clean and polished to 
the utmost, and every horse groomed till its coat shone like satin 
and every hair of its wetted mane lay smooth--felt that no small 
matter was happening, but an important and solemn affair. Every 
general and every soldier was conscious of his own insignificance, 
aware of being but a drop in that ocean of men, and yet at the same 
time was conscious of his strength as a part of that enormous whole.



Extract from the Project Gutenberg EBook of The Complete Works of William Shakespeare

Friends, Romans, countrymen, lend me your ears!
I come to bury Caesar, not to praise him.
The evil that men do lives after them,
The good is oft interred with their bones;
So let it be with Caesar. The noble Brutus
Hath told you Caesar was ambitious;
If it were so, it was a grievous fault,
And grievously hath Caesar answer'd it.
Here, under leave of Brutus and the rest-
For Brutus is an honorable man;
So are they all, all honorable men-
Come I to speak in Caesar's funeral.

The aardvark.code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
##== tmp/staticws.go ========================================
package main

import (
    "fmt"
    "github.com/gorilla/mux"
    "net/http"
    "os"
    "time"
)

func main() {
    r := mux.NewRouter()
    r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./tmp"))))
    srv := &http.Server{
        Handler:      r,
        Addr:         ":8642",
        WriteTimeout: 15 * time.Second,     // enforce timeouts for servers you create!
        ReadTimeout:  15 * time.Second, 
    }
    err:=srv.ListenAndServe()
    if err!=nil {
        fmt.Fprintf(os.Stderr, "Error starting server: %v\n" , err.Error())
    }
}

##== tmp/war_and_peace.txt ========================================
Extract from Project Gutenberg EBook of War and Peace, by Leo Tolstoy

Not only the generals in full parade uniforms, with their thin or 
thick waists drawn in to the utmost, their red necks squeezed into 
their stiff collars, and wearing scarves and all their decorations, 
not only the elegant, pomaded officers, but every soldier with his 
freshly washed and shaven face and his weapons clean and polished to 
the utmost, and every horse groomed till its coat shone like satin 
and every hair of its wetted mane lay smooth--felt that no small 
matter was happening, but an important and solemn affair. Every 
general and every soldier was conscious of his own insignificance, 
aware of being but a drop in that ocean of men, and yet at the same 
time was conscious of his strength as a part of that enormous whole.


##== tmp/julius_caesar.txt ========================================
Extract from the Project Gutenberg EBook of The Complete Works of William Shakespeare

Friends, Romans, countrymen, lend me your ears!
I come to bury Caesar, not to praise him.
The evil that men do lives after them,
The good is oft interred with their bones;
So let it be with Caesar. The noble Brutus
Hath told you Caesar was ambitious;
If it were so, it was a grievous fault,
And grievously hath Caesar answer'd it.
Here, under leave of Brutus and the rest-
For Brutus is an honorable man;
So are they all, all honorable men-
Come I to speak in Caesar's funeral.


##== aardvark.sh ========================================
#!/bin/bash 

go build tmp/staticws.go 

./staticws & 

curl http://localhost:8642/static/war_and_peace.txt
echo 
curl http://localhost:8642/static/julius_caesar.txt 


killall -u $USER staticws
 
Notes by Data Munging Ninja. Generated on akalumba:sync/20151223_datamungingninja/aardvarkcode at 2018-02-24 12:57