-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.js
52 lines (48 loc) · 1.9 KB
/
app.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
var host = process.env.VCAP_APP_HOST || 'localhost';
var port = process.env.VCAP_APP_PORT || 3000;
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname;
var filename = path.join(process.cwd(), uri);
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not Found\n");
response.end();
return;
}
if (filename.indexOf(".json") > 1) {
fs.readFile(filename, "binary", function(err, file) {
if(err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
return;
}
response.writeHead(200, {"Content-Type": "application/json"});
response.write(file, "binary");
response.end();
return;
});
} else {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<html><head><title>Activity Streams JSON Schemas</title></head><body>");
response.write("<h1>Activity Streams JSON Schemas</h1>");
response.write("<p>GitHub: <a href='https://github.com/activitystreams/json-schema'>");
response.write("https://github.com/activitystreams/json-schema</a></p>");
response.write ("<ul><li><a href='collection.json'>collection.json</a></li>");
response.write ("<li><a href='activity.json'>activity.json</a></li>");
response.write ("<li><a href='object.json'>object.json</a></li>");
response.write ("<li><a href='media_link.json'>media_link.json</a></li>");
response.write("</ul>");
response.write("</body></html>");
response.end();
return;
}
});
}).listen(port, null);
console.log('JSON Activity Streams Schema Server running at http://' + host + ':' + port + '/');