https://github.com/borgar/node-geir
Yet another node.js webserver
https://github.com/borgar/node-geir
Last synced: 19 days ago
JSON representation
Yet another node.js webserver
- Host: GitHub
- URL: https://github.com/borgar/node-geir
- Owner: borgar
- Created: 2010-09-02T17:55:47.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2013-03-14T14:49:31.000Z (about 13 years ago)
- Last Synced: 2025-03-22T06:45:44.982Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 114 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Geir - A simple node web server layer
Geir is a simple webserver layer for Node.js which pulls out ideas from Djanog and Sinatra. It's experimental, incomplete, undocumented, and not really recommended for production use.
## Getting it to run:
Include the server:
var Geir = require('./geir').Server;
var HttpResponse = require('./geir/http').HttpResponse
Create a new server:
var geir = new Geir;
Add a view:
geir.get( /^(.*?)$/, function( request, path ) {
var r = ['',
'\n',
'',
'You requested',
'\n',
'
You requested:
',
'' + path + '
',
'\n'];
return new HttpResponse( r.join('\n') );
});
Start listening to requests:
geir.listen( 8000 );
## The condensed version:
You can start listening as you create a server:
var g = new ( require('./geir').Server )( 8000 );
g.get( '/', function( request ) {
return '
It works!!';
});
### Magic:
Returning strings will make the server perform quick tests to try to determine their nature and tagged text will be served as `text/html`, unless a recognized doctype overrides it (svg and xml are currently supported). Returning an object will automatically serialize it and serve it as JSON.
### Async:
The HttpResponse object has a delay property, which will allow you to do hand over the data later, in case you're not generating an immediate response:
g.get( '/', function( request ){
var response = new HttpResponse( null, 'text/plain', 200 );
response.delay = true;
var dns = require('dns');
dns.resolve4('www.google.com', function (err, addresses) {
if (err) {
response.status_code = 400;
response.write( err.message );
response.flush();
};
response.write( 'addresses: ' + JSON.stringify(addresses) );
});
return response;
});
### TODO:
* Static file support
- A view that may be pointed at a directory that just takes care of it.
- Built in cacheing of some sort (or detection for the use of)
- Support for `if-modified-since`, `if-none-match`, `if-range headers`
* POST data support (at least for non-multipart)
* Some way to add custom 404 & 500 handlers
* Better/simpler handling of redirects