chnage static.js to run on node 0.8 as well
This commit is contained in:
parent
fa4b5d5474
commit
bbe951c73d
1 changed files with 11 additions and 7 deletions
18
static.js
18
static.js
|
|
@ -1,18 +1,22 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var http = require("http"),
|
var http = require("http")
|
||||||
url = require("url"),
|
, path = require("path")
|
||||||
path = require("path"),
|
, mime = require("mime")
|
||||||
fs = require("fs"),
|
, url = require("url")
|
||||||
mime = require("mime"),
|
, fs = require("fs")
|
||||||
port = process.env.PORT || 8888;
|
, port = process.env.PORT || 8888;
|
||||||
|
|
||||||
|
// compatibility with node 0.6
|
||||||
|
if (!fs.exists)
|
||||||
|
fs.exists = path.exists;
|
||||||
|
|
||||||
http.createServer(function(request, response) {
|
http.createServer(function(request, response) {
|
||||||
|
|
||||||
var uri = url.parse(request.url).pathname
|
var uri = url.parse(request.url).pathname
|
||||||
, filename = path.join(process.cwd(), uri);
|
, filename = path.join(process.cwd(), uri);
|
||||||
|
|
||||||
path.exists(filename, function(exists) {
|
fs.exists(filename, function(exists) {
|
||||||
if(!exists) {
|
if(!exists) {
|
||||||
response.writeHead(404, {"Content-Type": "text/plain"});
|
response.writeHead(404, {"Content-Type": "text/plain"});
|
||||||
response.write("404 Not Found\n");
|
response.write("404 Not Found\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue