tffileserver

0.0.13 • Public • Published

TF-FileServer

Provides files over HTTP. Also packages CSS and JS via TF-CSS and Browserify and allows callbacks for HTTP paths.

Example Usage

var fileserver = require('tffileserver');

// The first parameter is the path to files loaded into memory on boot.
// The second parameter is the path to files read from the hard drive for each request.
var server = fileserver.init(null, './www');

// We compile `index.js` using browserify and serve it over http at the path /bundle.js
fileserver.compileJavascript('./client_scripts/index.js', '/bundle.js');

// We combine css files using tfcss and serve the result over http at the path /style.css
fileserver.compileCSS('./client_styles/config.json', '/style.css');

fileserver.addAction('/test', function(req, resp) {
	resp.writeHead(200, {'Content-Type': 'application/json'});
	resp.end({'message': 'Hello World'});
});

server.listen(8080);

Note that req in the addAction callback would contain the following if the user request the page www.example.com/test.json?id=32&validate:

{
	"extension": "json",
	"filename": "/test.json",
	"parameters": {
		"id": "32",
		"validate": true
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i tffileserver

Weekly Downloads

15

Version

0.0.13

License

none

Last publish

Collaborators

  • twofront