-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for serving static files from a directory #142
Conversation
setProxyUpstreamHostHeader(proxy, u) | ||
} else { | ||
setProxyDirector(proxy) | ||
if u.Scheme == "http" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this a case statement (Go convention is to prefer case over if/else in many cases. pun intended =))
switch u.Scheme {
case "http", "https":
...
case "file":
...
default:
panic(fmt.Sprintf("unknown upstream protocol %s", u.Scheme))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I have switched to a case statement (I can make puns as well ;)) in a4feea9. The reason why I did the if/else is probably due to I normally work in Python, which doesn't have a switch/case statement.
@Tenzer this looks like a great first path. I think using the fragment as the path is clever. I need to think a little about what that means for typical configurations, and if there should be a way for us to support relative filesystem paths. In the mean time take a pass at README updates and I can always follow up with a future update for relative paths if needed. |
Hmm, tests are failing now due to the check of the scheme for the provided upstreams. I don't think there's an official way of supporting relative paths in file:// URLs. You would instead probably have to make a convention where I'll add some details to the README file. |
I have added a section to the README file now which describes a bit more in general how to configure upstreams as #12 also requested that. There may be changes that has to be made to the text, but we at least have something to base corrections upon now. |
I think the easiest way to fix the failing tests, is simply to remove the lines inside |
@Tenzer that or updating the value to |
The path should be provided as a file:// url with the full operating system path. An alias to where the directory is available as can be specified by appending a fragment (ie. "#/static/") at the end of the URL.
I opted for removing the lines since they aren't part of what is being tested. In case a later addition would check if the upstream is available before it get added the tests would fail again. The commits has been squashed and the tests has passed. Thanks for the guidance on adding this! |
Add support for serving static files from a directory
⭐ 🚀 🎉 awesome work! |
As discussed in #141, this adds the possibility of hosting static files with oauth2_proxy.
The path should be provided as a file:/// url with the full operating system path, ie.
file:///var/www/static/
.An alias to where the directory is available as can be specified by appending a fragment (ie. "#/static/") at the end of the URL, otherwise the full file path has to be entered in the URL when requesting the files.
Let me know if you have any comments on this. If not then I'll try to get it added to the README file.