function StaticServer(options) {
options = options || {};
if (!options.rootPath) {
throw new Error('Root path not specified');
}
if(!options.templates){
options.templates = {};
}
this.name = options.name;
this.host = options.host;
this.port = options.port;
this.cors = options.cors;
this.rootPath = path.resolve(options.rootPath);
this.followSymlink = !!options.followSymlink;
this.templates = {
'index': (options.templates.index || DEFAULT_INDEX),
'notFound': options.templates.notFound
};
if (options.index) {
console.log("options.index is now deprecated please use options.templates.index instead.");
this.templates.index = options.index;
}
Object.defineProperty(this, '_socket', {
configurable: true,
enumerable: false,
writable: true,
value: null
});
}n/a
function StaticServer(options) {
options = options || {};
if (!options.rootPath) {
throw new Error('Root path not specified');
}
if(!options.templates){
options.templates = {};
}
this.name = options.name;
this.host = options.host;
this.port = options.port;
this.cors = options.cors;
this.rootPath = path.resolve(options.rootPath);
this.followSymlink = !!options.followSymlink;
this.templates = {
'index': (options.templates.index || DEFAULT_INDEX),
'notFound': options.templates.notFound
};
if (options.index) {
console.log("options.index is now deprecated please use options.templates.index instead.");
this.templates.index = options.index;
}
Object.defineProperty(this, '_socket', {
configurable: true,
enumerable: false,
writable: true,
value: null
});
}n/a
function EventEmitter() {
EventEmitter.init.call(this);
}n/a
function StaticServer(options) {
options = options || {};
if (!options.rootPath) {
throw new Error('Root path not specified');
}
if(!options.templates){
options.templates = {};
}
this.name = options.name;
this.host = options.host;
this.port = options.port;
this.cors = options.cors;
this.rootPath = path.resolve(options.rootPath);
this.followSymlink = !!options.followSymlink;
this.templates = {
'index': (options.templates.index || DEFAULT_INDEX),
'notFound': options.templates.notFound
};
if (options.index) {
console.log("options.index is now deprecated please use options.templates.index instead.");
this.templates.index = options.index;
}
Object.defineProperty(this, '_socket', {
configurable: true,
enumerable: false,
writable: true,
value: null
});
}n/a
function EventEmitter() {
EventEmitter.init.call(this);
}n/a
function start(callback) {
this._socket = http.createServer(requestHandler(this)).listen(this.port, this.host, callback);
}...
followSymlink: true, // optional, defaults to a 404 error
templates: {
index: 'foo.html', // optional, defaults to 'index.html'
notFound: '404.html' // optional, defaults to undefined
}
});
server.start(function () {
console.log('Server listening to', server.port);
});
server.on('request', function (req, res) {
// req.path is the URL resource (file name) from server.rootPath
// req.elapsedTime returns a string of the request's elapsed time
});
...function stop() {
if (this._socket) {
this._socket.close();
this._socket = null;
}
}n/a