GithubHelp home page GithubHelp logo

httpdispatcher's People

Contributors

abdulhannanali avatar alberto-bottarini avatar christian1984 avatar cjbarth avatar enet4 avatar fizzygalacticus avatar supertassu avatar sxd1140 avatar th0r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

httpdispatcher's Issues

ReferenceError: chain is not defined

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?

Load resource issue

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.

Scenario 1

dispatcher.setStaticDirname(__dirname);
dispatcher.setStatic('resources');

Resource path:

.C:\Users\Renato\Desktop\resources\aeee.png

Scenario 2

dispatcher.setStaticDirname('.');
dispatcher.setStatic('resources');

Resource path:

.resources\aeee.png

Scenario 3

This is the only one that works.

dispatcher.setStaticDirname('');
dispatcher.setStatic('resources');

Resource path:

.\resources\aeee.png

setStatic does not work in node v13.0.1

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.

No Support for TypeScript

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.

static path regexp should be anchored to start of string

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

Load static resource error

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.

setStaticDirname is not working for "."

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("");

Static resource code doesn't sanity check URLs

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!

Readme is wrong

Example in the Readme is wrong

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

suggestion1

var HttpDispatcher = function() {
...
replace
this.staticFolderPrefix ; //old variable name
this.staticUrlPrefix ; //current variable name

thankyou great module

Error in HttpDispatcher#setStatic

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;
        }
        // ...
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.