Permalink
Browse files

Ported server to express--I couldn't get the paperboy version to work…

…, possibly because it was written against an older node.js (I'm on 0.4.8).
  • Loading branch information...
1 parent ca508b8 commit 0faac0f614f34528c8239f1aeb93c9e6f422097e @aslakhellesoy committed May 28, 2011
View
@@ -15,8 +15,10 @@ To actually take the code for a spin, concatenate the source files like so:
client/src/xhr_data_source.js client/src/live_search.js\
client/src/live_search.jquery.js > server/public/live-search.min.js
-Then run the server (you'll need Node.js)
+Then run the server (you'll need Node.js 0.4.8 or higher)
+ cd server
+ npm link
./run_server
Then visit http://localhost:8000/ and type something in the search box.
View
@@ -0,0 +1,2 @@
+node_modules/
+public/live-search.min.js
@@ -1,19 +0,0 @@
-Copyright (c) 2010 Debuggable Limited <felix@debuggable.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
@@ -1,99 +0,0 @@
-# Paperboy
-
-## Purpose
-
-A node.js module for delivering static files.
-
-## Features
-
- * Configurable callbacks on most events
- * ETag / 304 Support
- * Custom HTTP headers
-
-## Example
-
-Example from example/basic.js:
-
- var
- sys = require('sys'),
- path = require('path'),
- http = require('http'),
- paperboy = require('../lib/paperboy'),
-
- PORT = 8003,
- WEBROOT = path.join(path.dirname(__filename), 'webroot');
-
- http.createServer(function(req, res) {
- var ip = req.connection.remoteAddress;
- paperboy
- .deliver(WEBROOT, req, res)
- .addHeader('Expires', 300)
- .addHeader('X-PaperRoute', 'Node')
- .before(function() {
- sys.log('Recieved Request')
- })
- .after(function(statCode) {
- res.write('Delivered: '+req.url);
- log(statCode, req.url, ip);
- })
- .error(function(statCode,msg) {
- res.writeHead(statCode, {'Content-Type': 'text/plain'});
- res.write("Error: " + statCode);
- res.close();
- log(statCode, req.url, ip, msg);
- })
- .otherwise(function(err) {
- var statCode = 404;
- res.writeHead(statCode, {'Content-Type': 'text/plain'});
- log(statCode, req.url, ip, err);
- });
- }).listen(PORT);
-
- function log(statCode, url, ip,err) {
- var logStr = statCode + ' - ' + url + ' - ' + ip
- if (err)
- logStr += ' - ' + err;
- sys.log(logStr);
- }
-
-## API Docs
-
-### paperboy.deliver(webroot, req, res,opts,callbacks)
-
-Checks the `webroot` folder if it has a file that matches the `req.url` and streams it to the client. If `req.url` ends with a '/' (slash), 'index.html' is appended automatically.
-
-Parameters:
-
-* `webroot`: Absolute path where too look for static files to serve
-* `req`: A `http.ServerRequest` object
-* `res`: A `http.ServerResponse` object
-* `opts`: An object containing optional config parameters (only 'Expires' at the moment (in seconds))
-* `callbacks`: An object containing all callbacks described below:
-
-#### before()
-
-Fires if a matching file was found in the `webroot` and is about to be delivered. The delivery can be canceled by returning `false` from within the callback.
-
-#### after(statCode)
-
-Fires after a file has been successfully delivered from the `webroot`. statCode contains the numeric HTTP status code that was sent to the client
-
-#### error(statCode,msg)
-
-Fires if there was an error delivering a file from the `webroot`. statCode contains the numeric HTTP status code that was sent to the clientmsg contains the error message. You must close the connection yourself if the error callback fires!
-
-#### otherwise(err)
-
-Fires if no matching file was found in the `webroot`. Also fires if `false` was returned in the `delegate.before()` callback. If there was a problem stating the file, `err` is set to the contents of that error message.
-
-#### addHeader(name,value)
-
-Sets an arbitrary HTTP header. The header name `Expires` is special and expects the number of seconds till expiry, from which it will calculate the proper HTTP date.
-
-## License
-
-Paperboy is licensed under the MIT license.
-
-## Credits
-
-* [Jan Lehnardt](http://twitter.com/janl) for coming up with the name "Paperboy"
@@ -1,41 +0,0 @@
-var
- sys = require('sys'),
- path = require('path'),
- http = require('http'),
- paperboy = require('../lib/paperboy'),
-
- PORT = 8003,
- WEBROOT = path.join(path.dirname(__filename), 'webroot');
-
-http.createServer(function(req, res) {
- var ip = req.connection.remoteAddress;
- paperboy
- .deliver(WEBROOT, req, res)
- .addHeader('Expires', 300)
- .addHeader('X-PaperRoute', 'Node')
- .before(function() {
- sys.log('Recieved Request')
- })
- .after(function(statCode) {
- res.write('Delivered: '+req.url);
- log(statCode, req.url, ip);
- })
- .error(function(statCode,msg) {
- res.writeHead(statCode, {'Content-Type': 'text/plain'});
- res.write("Error: " + statCode);
- res.close();
- log(statCode, req.url, ip, msg);
- })
- .otherwise(function(err) {
- var statCode = 404;
- res.writeHead(statCode, {'Content-Type': 'text/plain'});
- log(statCode, req.url, ip, err);
- });
-}).listen(PORT);
-
-function log(statCode, url, ip,err) {
- var logStr = statCode + ' - ' + url + ' - ' + ip
- if (err)
- logStr += ' - ' + err;
- sys.log(logStr);
-}
Deleted file not rendered
@@ -1,11 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html lang="en">
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Paperboy Example</title>
-</head>
-<body>
- <h1>It works!</h1>
- <img src="/img/paperboy.jpg">
-</body>
-</html>
@@ -1 +0,0 @@
-module.exports = require('./lib/paperboy');
Oops, something went wrong.

0 comments on commit 0faac0f

Please sign in to comment.