Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between middleware and handlers which respond #16

Open
oliverbrooks opened this issue Jun 30, 2016 · 1 comment
Open

Distinguish between middleware and handlers which respond #16

oliverbrooks opened this issue Jun 30, 2016 · 1 comment
Milestone

Comments

@oliverbrooks
Copy link
Contributor

Use case:

I have an app in which some routes are only relevant on the server. When I do a GET or POST to these routes I want the request to perform a full HTTP request rather than attempt an XHR and 404.

This is currently possible by using a fully qualified URL which isorouter treats as a full page refresh but it requires knowledge that route x needs this special treatment.

Would propose that the route matching return false if there is no handler which matches the given pathname. For example.

isomorphic_routes.js

isorouter.use(middleware1);
isorouter.use(middleware2);

isorouter.get("/fish", function () {});

server_routes.js

router.get("/face", function () {});

If you hit this app with GET /fish it will run middleware 1 and 2 and also the fish handler and do so on both client and server side.

If you hit this app with GET /face' with HTTP it will handle the request but fail from a loaded client app. If you tap a link to/face` it will run through the middleware and fail silently. Sad face.

Would be nice if isorouter could detect that there is no handler for a pathname matching the link <a href="/face"> and perform a HTTP request.

In the current code this would involve returning false to router.go() called from lib/dom_event_listener.js so the event isn't cancelled. This could be done by modifying the go method in browser.js to only return true if there was one or more route match (ignore middleware).

@orangemug
Copy link
Owner

I guess the other method would be to guard around the server side routes

app.get("/serverOnly", passThroughServer, function() {})

passThroughServer could then just redirect the page

Then the server / client code can live in the the same place in the codebase.

Not sure if thats a good idea but thought I'd put it out there

@orangemug orangemug added this to the v0.6.0 milestone Jun 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants