Git Product home page Git Product logo

stick's People

Contributors

botic avatar earl avatar ehoogerbeets avatar grob avatar hns avatar kmfdm1 avatar oberhamsi avatar oravecz avatar robi42 avatar rrmckinley avatar siberex 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  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stick's Issues

Implement route() function

Implement a route function to make something like this (new in Express 4.0) possible:

app.route('/myroute')
.all(function(req) {
  // runs for all HTTP verbs first
  // think of it as route specific middleware!
})
.get(function(req) {
  return response.json({});
})
.post(function(req) {
  // some code
});

Typo in middleware/params.js

Line 71 should be;

postParams = JSON.parse(this.input.read().decodeToString(encoding));

instead of;

postParams = JSON.parse(this.input.read.decodeToString(encoding));

it was using read() as an attribute of input, which triggered the following error

TypeError: Cannot find function decodeToString in object function read()

Running stick on localhost

I use Windows 7.
To try stick, I unzipped ringoJS on c:\ringo..then I unzipped stick in c:\ringo\stick.

When I run c:\ringo\stick\examples\demo.js it throws an error that stick [from require("stick")] is not found.

After half hour of blog search and self tricks, I found that you need to do 2 things -

Create a folder named stick under c:\ringo\packages path.

Then move the files under c:\ringo\stick\lib to this c:\packages\STICK directory.

run in DOS CMD below:
ringo -m packages/stick stick/examples/demo.js

Bingo ! Stick worked in localhost:8080

Hannes...Can you please fix the above issue asap ?

Unlike you previous post in several blogs the above manual path issue still exists and needs to be fixed.

Hope this helps many !

Thanks !

Drop continuation middleware

jetty-continuation has been dropped . The next stick release will remove the (now legacy) continuation middleware.

app.render(skin, context) requires context

At the moment it's not possible to render a template without a context object:

app.render("test.html");

This results in "TypeError: Cannot set property "content" of undefined to "WTF?!" (stick/lib/middleware/render.js#52)", which might confuse beginners, who just want to render a basic template without any variables.

The following works:

app.render("test.html", {});

Add cache control middleware

The static middleware does not support any caching right now. This is problematic for larger files. We should add a general purpose cache / cache header middleware for that, that adds cache headers for the provided content types. This could follow the Apache webserver config approach.

app.cacheControl({
   "image/png": { "maxAge": 500, "no-transform": true }
});

redirectTo() helper does not accept "/" as action

I think this is a bug in the reverse lookup with "/". If I change the binding to {action: "/someAction" } it works as expected.

var {Application} = require("stick");
var {redirectTo} = require("stick/helpers"); 
var log = require("ringo/logging").getLogger(module.id);
var fs = require("fs");

var app = exports.app = Application();

var response = require("ringo/jsgi/response");

app.configure("params", "upload", "route");

app.post("/uploadImage", function(req) {
   if (req.postParams.formFileInput && req.postParams.formFileInput.value.length > 0) {
      fs.write(module.resolve("files/" + req.postParams.formFileInput.filename), req.postParams.formFileInput.value);

      // This redirects to http://localhost:8080/upload/_/_(unknown_route)
      return redirectTo(app, {
         action: "/"  // <----- FAILS with: Error: Unhandled request (stick/lib/stick.js#193) 
      });
   }

   return response.html("<html><body><h1>Upload failed.</h1></body></html>");
});

app.get("/", function(req) {
   return response.html("<html><head><title>File Upload Demo</title></head> \
         <body><form method='POST' action='uploadImage' enctype='multipart/form-data'> \
         <h1>Upload:</h1> \
         <input type='file' name='formFileInput' /><hr/><input type='submit' value='Upload' /> \
         </form></body> \
      </html>");
});

Access to the current Application

Proprosal: Get a reference to the current Application() object in scope using a call similar to Application.currentApp.

Need: This will allow functions which are not part of the normal call flow to get access to the Application object, and thus the JSGI requests object. From here, the current request can be retrieved using Application.currentApp.request.

Support URI templates in route path spec

It would be nice to have the URI template format supported in the route middleware path spec. In other words in addition to "/post/:id" it would be great to also be able to provide "/post/{id}". URI templates seem to be more widely adopted and have the backing of W3C.

JSGI response.headers -> "keys MUST be lower case" not fulfilled in some middlewares

found in
basicauth.js:
return { // Access denied.
status: 401,
headers: {
'Content-Type': 'text/html',
'WWW-Authenticate': 'Basic realm="Secure Area"'
},
body: [
...

error.js:
return {
status: 500,
headers: {"Content-Type": "text/html"},
body: [html]
};

notfound.js:
return {
status: 404,
headers: {"Content-Type": "text/html"},
body: [body]
};

render.js:
return {
status: 200,
headers: {"Content-Type": contentType + "; charset=" + charset},
body: [content]
};

Either use ringo/utils/http.js's Headers utility or always use lower-case keys.

Most specific match in route middleware

There is an improvement opportunity with the route middleware.

Consider this case:

app.get('/foo/:userid', function() {...});
app.get('/foo/bar', function() {...});

It would be advantageous if a request for '/foo/bar' matched '/foo/bar' instead of '/foo/:userid'.

Make Stick Lazily Load Mounted Modules

https://groups.google.com/forum/#!topic/ringojs/YZmU1SXGZ4k

Presently, all modules that are mounted using Stick's mount middleware are evaluated prior to routing the request to the module which actually needs to handle a request. For a large site, this could result in a lot of code being evaluated that doesn't need to be. While this only affects the initial request (since the module objects are cached), the cost of those loading requests could be high for large sites.

CORS middleware: response.addHeaders() not always available

Stick's mount middleware returns a plain JS response object in case of a missing trailing slash. The current CORS middleware however [relies](https://github.com/ringo/stick/blob/master/lib/middleware/cors.js#L62 et.al.) on the response object's method .addHeaders(), which leads to an exception. This also happens if using .redirect() or .notModified() of the standard RingoJS jsgi utility module, see ringo/ringojs#257.

Probably the easiest fix would be to modify stick to utilize the RingoJS response utility module (there's also a redirectTo() helper method that would need to change). Otoh it would make sense avoid .addHeaders() calls, as this won't force applications to use the response util module.

stick can not be installed.

Hi,
tried to install stick on ringo under Win XP:

a) based on the binary RingoJS v0.7.0 tar.gz archive

downloaded ringojs-0.7.tar.gz from the ringo website.
I get this log, this is no problem because there is no ringo/jsgi directory:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\ringo\bin>ringo-admin install hns/stick
Downloading http://github.com/hns/stick/zipball/master
Installing package stick
 + C:\ringo\bin\\packages\stick\LICENSE
(... downloads everything ...)
 + C:\ringo\bin\\packages\stick\update-docs.sh
Done
Error: failed to remove file C:\systemp\nils\ringo-install1572099501524327036.zip (fs.js#460)

C:\ringo\bin>cd packages\stick

C:\ringo\bin\packages\stick>ringo demo.js
Wrapped java.io.IOException: Resource "ringo/jsgi/response" not found or not readable (stick/middleware/static.js#12)
        at stick/middleware/static.js:12
        at stick/middleware.js:46
        at stick.js:19
        at C:\ringo\bin\packages\stick\demo.js:4


C:\ringo\bin\packages\stick>

b) based on the RingoJS master tar.gz git snapshot

downloaded ringo-ringojs-v0.7.0-85-g11170e4.tar.gz from the same website.
I get this log, i do not understand this, because C:/ringo/bin/packages/stick/lib/stick exists:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\ringo\bin>ant jar
Buildfile: C:\ringo\bin\build.xml

init:

compile:
    [mkdir] Created dir: C:\ringo\bin\build\classes
    [javac] Compiling 48 source files to C:\ringo\bin\build\classes

jar:
      [jar] Building jar: C:\ringo\bin\lib\ringo.jar
      [jar] Building jar: C:\ringo\bin\run.jar

BUILD SUCCESSFUL
Total time: 2 seconds

C:\ringo\bin>ringo-admin install hns/stick
Downloading http://github.com/hns/stick/zipball/master
Installing package stick
 + C:\ringo\bin\\packages\stick\LICENSE
(... downloads everything ...)
 + C:\ringo\bin\\packages\stick\update-docs.sh
Done
Error: failed to remove file C:\systemp\nils\ringo-install6510812854526382940.zip (fs.js#480)

C:\ringo\bin>cd packages\stick

C:\ringo\bin\packages\stick>ringo demo.js
Cannot find module 'stick' (C:\ringo\bin\packages\stick\demo.js#4)
        at C:\ringo\bin\packages\stick\demo.js:4


C:\ringo\bin\packages\stick>

c) i tried it with a fresh clone direct from gitHub

behaves like b)

In short, i was not able to install stick.

Greets, Nils-Hero

Display unhandled request URL

If a route is not defined, Stick prints out the following stack trace:

Error: Unhandled request
    at stick/lib/stick.js:187 (unhandled)
    at stick/lib/middleware/route.js:220 (route)
    at stick/lib/middleware/mount.js:125 (mount)
    at stick/lib/middleware/params.js:102 (anonymous)
    at stick/lib/middleware/upload.js:48 (upload)
    at /Users/philipp/Documents/collodion/app/security.js:19 (accessControl)
    at stick/lib/stick.js:37 (app)
    at ringo/jsgi/connector.js:42 (handleRequest)

It would help to see which route failed. A typical case is "/favicon.ico".

Mounts not sorted prior to searching

If I have the following two mounts defined:
app.mount('/', module.resolve('test1/config'));
app.mount('/test2', module.resolve('test2/config'));

The first one will always match the incoming url. It is probably best to sort the mounts by least specific prior to matching. Least specific in this case would be determined by the number of slashes in the spec.path. In the above example, the trailing slash is removed from all paths, so the first mount actually becomes "" and the second is "/test2".

File upload example

It would be nice to have a file upload example to showcase the upload middleware. It's unclear how to use it without looking at the middleware code itself.

CORS middleware doesn't immediately return on preflight requests.

09:58 < Eleeleth> Is there a reason preflights don't immediately return from the middleware?
09:59 < oberhamsi> Eleeleth: hm, good question
09:59 < oberhamsi> i'm investigating now.
10:00 < oberhamsi> i did write a lot of unit tests for cors. wow :)
10:05 < oberhamsi> ok that's a serious bug: preflight request should instantly return. currently it executes the route
10:07 < Eleeleth> yeah. That's the behaviour I was confused about.
10:08 < oberhamsi> yeah, very dangerous behaviour.

Make Stick work with Common Node

My fork of Stick works with Common Node for the most part (while still working with Ringo) but it's rough around the edges. It would be good to come to some agreement on how to address these rough edges, clean up my fork and merge it back in. I'll list the changes I made below:

  • there's no destructuring assignment in V8, so I've changed the require lines accordingly
  • module.resolve doesn't exist in Node (there is require.resolve, but it doesn't work on directories), so I've refactored it out into a global resolve function - perhaps there's a neater cross platform solution here?
  • there are a number of pure JS utility modules that are part of Ringo but aren't part of any CommonJS spec (yet?) so I've split them out into a generic utility modules package called common-utils as well as HTTP specific ones in stick/lib/utils
  • the profiler and continuation middleware depend on Rhino, so I've commented them out, same with zip middleware
  • Stick relies on ServletRequest in a few places, so I've created dummy objects for that
  • according to the CommonJS IO spec, Binary isn't an array, so I pre-convert to an array
  • I've added getResource to common-node even though it's not part of any CommonJS spec, but instanceof org.ringojs...Resource doesn't work

There's also a few other open issues that I haven't addressed yet.

Any comments or suggestions would be greatly appreciated.

CORS middleware should handle OPTIONS requests

it has all the info it needs to provide the right response and it's its job to deal with CORS to avoid repeating the same code in the views.

if an application really wants to see the OPTIONS request, we could add a forwardOptions option to the middleware.

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.