depado / goploader

Easy file sharing with server-side encryption, curl/httpie/wget compliant
https://docs.gpldr.in
MIT License
274 stars 41 forks source link

Serve from several domains #72

Open daftaupe opened 4 years ago

daftaupe commented 4 years ago

Hello,

I think it would be helpful to be able to specify several servernames, so that one instance of goploader could be used for different domains/subdomains. Would it be possible to form the returned URL of the document via the Host header in the coming request ?

Regards,

daftaupe commented 4 years ago

I sort of did it with the following changes :


diff --git a/server/views/resources.go b/server/views/resources.go
index 039237d..4521492 100644
--- a/server/views/resources.go
+++ b/server/views/resources.go
@@ -82,7 +82,7 @@ func CreateC(c *gin.Context) {
                return
        }
        res.OnCreated(c)
-       c.String(http.StatusCreated, "%s/v/%s/%s\n", utils.ServerURI(c), res.Key, k)
+       c.String(http.StatusCreated, "%s/v/%s/%s\n", utils.DetectScheme(c) + "://" + c.Request.Host, res.Key, k)
 }

 // ViewC handles the file views for encrypted files

What do you think about that modification ?

For the record it requires to use proxy_set_header Host $host; when reverse-proxying with nginx.

depado commented 4 years ago

Hello, First of all thanks for your interest in this project.

I found this middleware that maybe could be used to have a more generic way of handling that. (In which case, we could just use location.Get(c) instead of the utils package). This middleware also allows to define which headers are taken into account and supports defaults. I feel that it would make things simpler.

What do you think?

daftaupe commented 4 years ago

@Depado that sounds much better than my quick hack indeed !

But unfortunately I don't have that much time to hack on goploader :/

depado commented 4 years ago

I'll have a look when I have some time then :)