-
Notifications
You must be signed in to change notification settings - Fork 1
/
tenkion.js
121 lines (110 loc) · 2.79 KB
/
tenkion.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Tenkion NodeJS Web Server
* Created By: aq@okaq.com
* On: 04/05/2011
* Running: nodejs v0.4.5
*/
var tenkion = {
"init": function() {
// modules
this.http = require('http');
this.fs = require('fs');
this.url = require('url');
// static_files
var nile0 = new nile();
this.niles = [
new nile(nile0.a[0], nile0.b[0], nile0.b[5]),
new nile(nile0.a[1], nile0.b[0], nile0.b[3]),
new nile(nile0.a[2], nile0.b[0], nile0.b[5]),
new nile(nile0.a[3], nile0.b[0], nile0.b[3]),
new nile(nile0.a[4], nile0.b[0], nile0.b[5]),
new nile(nile0.a[5], nile0.b[0], nile0.b[5]),
new nile(nile0.a[6], nile0.b[0], nile0.b[5]),
new nile(nile0.a[7], nile0.b[0], nile0.b[5])
];
this.load();
this.serve();
},
"load": function() {
for (var i = 0; i < this.niles.length; i++) {
// async readFile index closure out of sync
/*
this.fs.readFile(
this.niles[i].url.slice(1),
this.niles[i].enc,
function(err, data) {
if (err) {
console.log("fs.readFile arror reading file: " + tenkion.niles[i].url + ". Error message: " + err);
tenkion.niles[i].fd = "";
}
console.log("tenkion.niles[i]: " + tenkion.niles[i] + ". i:" + i);
tenkion.niles[i].fd = data;
}
);
*/
this.niles[i].fd = this.fs.readFileSync(this.niles[i].url.slice(1), this.niles[i].enc);
}
},
"serve": function() {
this.server =
this.http.createServer(function(req, res) {
var i0;
if (req.url == "/") {
i0 = 1;
} else if (req.url == "/speed") {
i0 = 3;
} else {
i0 = tenkion.niles[0].a.indexOf(req.url);
}
if (i0 != undefined && i0 != -1) {
res.writeHead(200, tenkion.niles[i0].hdr);
res.end(tenkion.niles[i0].fd);
} else {
res.writeHead(200, tenkion.niles[0].b[2]);
res.end("The app you requested: " + req.url + " does not exist.\n" + (new Date().toUTCString()));
}
});
console.log("okaq.com web server (tenkion) started. Listening on port 8000...");
this.server.listen(8000, "127.0.0.1");
}
}
function nile(u0, e0, h0) {
this.enc = e0;
this.url = u0;
this.fd = undefined;
this.hdr = {'Content-Type':h0};
}
nile.prototype.b = [
"utf-8",
"gzip",
"text/plain",
"text/html",
"text/css",
"text/javascript"
];
nile.prototype.a = [
"/ab/okaq.js",
"/ab/okaq.html",
"/ab/motd.js",
"/ab/speed.html",
"/ab/speed.js",
"/ab/leek.js",
"/ab/chardata.js",
"/ab/naif.js"
];
tenkion.init();
// NOTES
// nextus: use fs.readdir()
/* kokaqu is our tools app
// located in chicha to expose to user
// kigu: grid drawing tool (color, export to json)
"/kokaqu/ko.html",
"/kokaqu/ko.js",
"/kokaqu/kigu.html",
"/kokaqu/kigu.js"
*/
/* okaq.com/machi is the new grid draw animator
* run on separate nodejs server instance
* actually want one server on port 80 no redirect
* handle cookies for session management
*/