1.0.0 • Published 12 months ago

static-files v1.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
12 months 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

12 months ago

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago