Skip to content

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

@botic

Description

@botic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions