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

How to detect if path does not exist 404 #41

Closed
digitaldesigndj opened this issue Sep 25, 2015 · 5 comments
Closed

How to detect if path does not exist 404 #41

digitaldesigndj opened this issue Sep 25, 2015 · 5 comments
Labels
feature New functionality or improvement

Comments

@digitaldesigndj
Copy link

I am trying to setup a cache proxy thing, if the file is on disk I want to just serve it up, otherwise I'll proxy the request, pipe the response to the client, and write the file to disk. I have the code for the proxy working fine, I would just like to hook into reply.file() if it is going to return a 404 error. Is this possible, or beyond the scope of this module?

@hueniverse
Copy link
Contributor

You can do this now with onPreResponse extension. Not as clean as a native extension to this module where you can specify an error handler fallback. But also not sure if it's worth the complexity here. I'll let @kanongil decide.

@digitaldesigndj
Copy link
Author

Thanks for the help, that's exactly what I needed. There's a little bit of new route detection that I had to do, but it may actually be cleaner this way.

That could just be because my app is small right now however.

@kanongil
Copy link
Contributor

I agree with the approach @hueniverse offered, though I would probably use a plain directory handler, and handle the proxy behavior in the onPreResponse hook.

To detect when to apply this behavior, as the hook is called for all routes, you can use the app route config, which can be accessed from the extension point handler via request.route.settings.app.

I will leave this request open for now in case others want to chime in but I don't really think it is worth the effort to include this functionality in inert.

@digitaldesigndj
Copy link
Author

I did look at onPreResponse I can't still say for sure why I didn't take that route, but I can say that I looked at it for a bit. I can say also that this proxy stuff is super helpful when injecting node.js into a stale corporate environment. Even if the application was small, it came together quick.

This app really tears the face off of a bad site, and it's gonna take a crowbar to get this sucker off.

@Marsup Marsup added feature New functionality or improvement and removed request labels Sep 21, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

4 participants