alberto-bottarini / httpdispatcher Goto Github PK
View Code? Open in Web Editor NEWSimple httpdispatcher for node.js
License: MIT License
Simple httpdispatcher for node.js
License: MIT License
I copied and pasted the example and tried running it on node v6.2.1 and I got the ReferenceError error for chain. I see that there was an issue open that is now closed.
How can I resolve this error?
For relative path, anything different from dispatcher.setStaticDirname('');
makes httpdispatcher unable to find the pages resources. They just do not get loaded.
This is due to line number 79 in httpdispatcher.js in which it is found
var filename = "." + require('path').join(this.staticDirname, url.pathname);
If static dir name is not set, an exception is thrown. If it is set to anything but an empty string for relative paths, it prepends a '.' to the beggining of the resource path, making it unable to be found.
dispatcher.setStaticDirname(__dirname);
dispatcher.setStatic('resources');
Resource path:
.C:\Users\Renato\Desktop\resources\aeee.png
dispatcher.setStaticDirname('.');
dispatcher.setStatic('resources');
Resource path:
.resources\aeee.png
This is the only one that works.
dispatcher.setStaticDirname('');
dispatcher.setStatic('resources');
Resource path:
.\resources\aeee.png
Hello, is it possible to add support for PUT and DELETE methods ?
Gread module, btw.
The problem seems to be in the use of util.inspect() in HttpDispatcher.urlMatches.
The line:
if(util.inspect(config) == "[Function]") return config(url);
In 13.0.1 util.inspect return "[Function] Anonymous" with a static url and fails this test.
In your readme example, it uses 'chain'. Where/what is this please?
I noticed that there is no TypeScript support for this module either in your project or in DefinitelyTyped. Thus, I created a httpdispatcher.d.ts file for you to include in your project. I didn't include it in DefinitelyTyped's repository because I don't care to write all those tests. If you'd like the file in your project for all us TypeScript users, I'd be glad to make a PR.
Thanks alberto for this library.
I am wondering if 2.2 is going to be pushed to npm soon.
Cheers ;-)
In setStatic
the regexp should be anchored to the start of a string, e.g.
RegExp("^\/"+folder)
otherwise given a call to dispatcher.setStatic('foo')
the dispatcher will match any path containing /foo
instead of one that starts /foo
There is no required module "mime" in dependances in package.json.
I don't know how work npm, but in package's page ( https://www.npmjs.com/package/httpdispatcher ) last version is 1.0.0, and downloaded code is equivalent to code by tag 1.0.0, but in git-repository last tag - 1.1.0
[Sorry for my english]
Or, do I need to "roll my own?"
Thank you for any information you can provide.
I have followed what is written here
https://www.npmjs.com/package/httpdispatcher
But this is not working
Kindly assist
Hi thanks for this module, I had a problem ln serving images, look at here
It's a breaking change. That means it should be 2.0.0.
Hi,
i'm using httpdispatcher. I think it's very useful.
dispatcher.setStaticDirname('static');
dispatcher.setStatic('/resources');
to access static resources in ./static directory (relative to the package root) and get an error in this line
"Content-Type": require('mime').lookup(filename)
^
this is because mime package has renamed lookup() to getType()
I've changed httpdispatcher.js:131 accordingly
"Content-Type": require('mime').getType(filename)
now it works fine.
Thanks.
As line 79 is var filename = "." + require('path').join(this.staticDirname, url.pathname);
, we should not use this method with ".". It will generate a path like this: ".public" instead of "./public".
One solution for this is: setStaticDirname("");
It's possible to subvert the system to dish out copies of system files by sending an HTTP request of e.g.
GET /resources/../../../../../etc/passwd HTTP/1.0
This is a major security flaw!
var dispatcher = require('./httpdispatcher');
dispatcher.setStatic('resources');
here need a statment like this:
var dispatcher = require('./httpdispatcher');
dispatcher.setStatic('resources');
//this statment!
dispatcher.setStaticDirname('.');
otherwise node will report an Error of package 'Path'.Because the variable in httpdipatcher.js this.staticDirname
var HttpDispatcher = function() {
...
replace
this.staticFolderPrefix ; //old variable name
this.staticUrlPrefix ; //current variable name
thankyou great module
function(req, res, chain) in place of function(req, res)
HI,
Can you add the licensing information if applicapable
HttpDispatcher.prototype.setStatic = function(folder) {
this.on('get', new RegExp("\/"+folder), this.staticListener);
}
this.staticListener here is unbound to HttpDispatcher instance, so "staticListener" handler is crashs when there is no file found in fs.
HttpDispatcher#staticListener:
// ...
var errorListener = this.errorListener;
require('fs').readFile(filename, function(err, file) {
if(err) {
errorListener(req, res);
return;
}
// ...
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.