Skip to content

Option to allow URLs that contain a dot (.) to be rewritten #25

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

Closed
fixpunkt opened this issue May 6, 2016 · 10 comments
Closed

Option to allow URLs that contain a dot (.) to be rewritten #25

fixpunkt opened this issue May 6, 2016 · 10 comments

Comments

@fixpunkt
Copy link

fixpunkt commented May 6, 2016

Hi there,

I've got a use case that is a little different:

My view URLs may actually contain dots as part of the URL (because I pass quoted URLs as a path parameter). For this to work I'd need the following:

Would you be willing to consider this use case?

Cheers,

Jannik

@fixpunkt
Copy link
Author

fixpunkt commented May 6, 2016

Seems to be kind of a duplicate of #17. I'm leaving this open for now to document that more than one person actually has a need for this feature, but feel free to close if you think it's too esoteric.

I'll resort to hacking my own middleware for now.

@bripkens
Copy link
Owner

bripkens commented May 6, 2016

@fixpunkt: This topic has come up multiple times now. So I'd inclined to solve it with this middleware. Would #22 solve your use case with a few changes? I am thinking about merging #22 and changing the contents of the ignorePaths array to be a regex.

If this solves your use case, I'll merge and release this asap.

@fixpunkt
Copy link
Author

fixpunkt commented May 6, 2016

Unfortunately, #22 only fixes part of the problem. I would also need a config option rewriteDots that disables this code path:

if (parsedUrl.pathname.indexOf('.') !== -1) {
  logger(
    'Not rewriting',
    req.method,
    req.url,
    'because the path includes a dot (.) character.'
  );
  return next();
}

#22 is required to alleviate the fallout of this: If I disable the "don't rewrite paths that contain dots" rule, I have no way to continue serving my static assets, so I'll have to add ignorePaths: ['/assets/'] as enabled by #22.

@bripkens
Copy link
Owner

bripkens commented May 6, 2016

That sounds pretty complicated @fixpunkt. Is there no way for you to make use of the rewrites rule?

https://github.com/bripkens/connect-history-api-fallback#rewrites

@fixpunkt
Copy link
Author

fixpunkt commented May 7, 2016

Yeah, maybe something like {from: /^!(\/assets\/)/, to: '/index.html'} might work, but at that point this middleware gets kind of redundant.

I've ended up building a 3-line koa middleware that does this to solve my problem yesterday, so yeah, I guess we can close this issue. Thanks for your help!

@fixpunkt fixpunkt closed this as completed May 7, 2016
@domenkozar
Copy link

What is the best way of dealing with this? It's a really annoying behavior, some of my URLS include a dot because it's a valid URL character.

I'd like to understand better why . is considered a special case, doesn't file get first requested if this actually exist and only then fallback is used?

@bripkens
Copy link
Owner

bripkens commented Aug 7, 2016

@domenkozar: Since this has been request a bunch of times now, I added an option to disable the . rule. See the readme:

https://github.com/bripkens/connect-history-api-fallback#disabledotrule

The feature has been released as version 1.3.0 to NPM. Please let me know whether this solves your problem.

@bripkens bripkens reopened this Aug 7, 2016
@domenkozar
Copy link

@bripkens thanks! I wonder why dotrule is even needed? Shouldn't filesystem be accessed first and then fallback would go to history api?

@bripkens
Copy link
Owner

bripkens commented Aug 7, 2016

Shouldn't filesystem be accessed first and then fallback would go to history api?

In a perfect world, yes. Unfortunately, there are very many ways where this gets complicated:

  • What is the root directory for filesystem access?
  • Is filesystem access permitted for this user?
  • Is the file served in some kind of special way, e.g. by transformation from a template?

On top of all this, the dot rule has been part of this middleware since day 1 (worked perfect for my use case at that time) and I don't want to change the middleware's default settings (and by that upset other users for which this also works fine).

@bripkens
Copy link
Owner

Closing since this is implemented now.

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

3 participants