1.0.0 • Published 2 years ago

static-files v1.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
2 years ago

static-files

A simple node module for serving static files. Files are beeing cached for better performance.

usage

var http = require('http');
var sf = require('static-files');

http.createServer(function(request, response) {

	var config = {
			
		// root directory of your static files (here: folder "public" relative to "main.js")	
		rootPath : './public',
		
		// paths can be mapped to files directly (path : filePath)
		mappings : {
			
			'/welcome' : '/index.html',
			'/node/getIcon' : '/images/node.png'
		}
		
		// optional error handler (e.g. no file found for given path)
		onError : function(response, error) {
		
			response.setHeader('Content-Type', 'text/plain');

			if (error.code === 'ENOENT') {

			response.statusCode = 404;
			response.end('Nothing found here...');

			} else {
	
				response.statusCode = 500;
				response.end('Something went terribly wrong!!!');
			}
				
		}
		
	};
		
	// serve files via response for given configuration and request 	
	sf.serve(request, response, config);
	
}).listen(3000);
console.log('Please browse to localhost:3000/welcome or localhost:3000/index.html');
console.log('Please browse to localhost:3000/node/getIcon or localhost:3000/images/node.png');
1.0.0

2 years ago

0.7.0

11 years ago

0.6.1

11 years ago

0.6.0

11 years ago

0.5.0

11 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.0

11 years ago

0.2.0

11 years ago