mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
replaced all tabs with 4 spaces
This commit is contained in:
parent
5d11540c55
commit
26f3d22db7
30 changed files with 1017 additions and 1011 deletions
|
|
@ -1,71 +1,71 @@
|
|||
define([
|
||||
'http',
|
||||
'node-static'
|
||||
'http',
|
||||
'node-static'
|
||||
],
|
||||
|
||||
function(http, nodeStatic) {
|
||||
|
||||
function HttpServer(options) {
|
||||
options.port = options.port || 1234;
|
||||
options.caching = typeof options.caching != 'undefined' ? options.caching : true;
|
||||
options.rootDirectory = options.rootDirectory || './';
|
||||
function HttpServer(options) {
|
||||
options.port = options.port || 1234;
|
||||
options.caching = typeof options.caching != 'undefined' ? options.caching : true;
|
||||
options.rootDirectory = options.rootDirectory || './';
|
||||
|
||||
this.server = null;
|
||||
this.server = null;
|
||||
|
||||
this.init(options);
|
||||
}
|
||||
this.init(options);
|
||||
}
|
||||
|
||||
HttpServer.prototype.init = function(options) {
|
||||
var self = this;
|
||||
HttpServer.prototype.init = function(options) {
|
||||
var self = this;
|
||||
|
||||
var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching });
|
||||
var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching });
|
||||
|
||||
this.server = http.createServer(
|
||||
function(req, res){
|
||||
req.addListener('end', function () {
|
||||
switch(true) {
|
||||
case req.url == '/':
|
||||
fileServer.serveFile('./static/html/index.html', 200, {}, req, res);
|
||||
break;
|
||||
this.server = http.createServer(
|
||||
function(req, res){
|
||||
req.addListener('end', function () {
|
||||
switch(true) {
|
||||
case req.url == '/':
|
||||
fileServer.serveFile('./static/html/index.html', 200, {}, req, res);
|
||||
break;
|
||||
|
||||
case req.url == '/client.js':
|
||||
fileServer.serveFile('./client.js', 200, {}, req, res);
|
||||
break;
|
||||
case req.url == '/client.js':
|
||||
fileServer.serveFile('./client.js', 200, {}, req, res);
|
||||
break;
|
||||
|
||||
case req.url == '/require.js':
|
||||
fileServer.serveFile('./node_modules/requirejs/require.js', 200, {}, req, res);
|
||||
break;
|
||||
case req.url == '/require.js':
|
||||
fileServer.serveFile('./node_modules/requirejs/require.js', 200, {}, req, res);
|
||||
break;
|
||||
|
||||
case new RegExp(/^\/app/).test(req.url):
|
||||
fileServer.serve(req, res, function(){
|
||||
self.handleFileError(res)
|
||||
});
|
||||
break;
|
||||
case new RegExp(/^\/app/).test(req.url):
|
||||
fileServer.serve(req, res, function(){
|
||||
self.handleFileError(res)
|
||||
});
|
||||
break;
|
||||
|
||||
case new RegExp(/^\/static/).test(req.url):
|
||||
fileServer.serve(req, res, function(){
|
||||
self.handleFileError(res)
|
||||
});
|
||||
break;
|
||||
case new RegExp(/^\/static/).test(req.url):
|
||||
fileServer.serve(req, res, function(){
|
||||
self.handleFileError(res)
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
self.handleFileError(res);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
this.server.listen(options.port);
|
||||
}
|
||||
default:
|
||||
self.handleFileError(res);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
this.server.listen(options.port);
|
||||
}
|
||||
|
||||
HttpServer.prototype.getServer = function(){
|
||||
return this.server;
|
||||
}
|
||||
HttpServer.prototype.getServer = function(){
|
||||
return this.server;
|
||||
}
|
||||
|
||||
HttpServer.prototype.handleFileError = function (res){
|
||||
res.writeHead(404, {'Content-Type': 'text/html'});
|
||||
res.end('<h1>404 not ... found</h1>');
|
||||
}
|
||||
HttpServer.prototype.handleFileError = function (res){
|
||||
res.writeHead(404, {'Content-Type': 'text/html'});
|
||||
res.end('<h1>404 not ... found</h1>');
|
||||
}
|
||||
|
||||
return HttpServer;
|
||||
return HttpServer;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue