Repository: learningequality/kolibri

Issue:
Cannot serve serving resources in storage when a custom KOLIBRI_URL_PATH_PREFIX is used
<!--
Instructions:
 * Fill out the sections below, replace …'s with information about your issue
 * Use the 'preview' function above this text box to verify formatting before submitting
-->

### Observed behavior
<!--
Description of the behavior that was observed, including screenshots or other references when applicable
-->

* Start Kolibri with: `KOLIBRI_URL_PATH_PREFIX=/kolibri KOLIBRI_HTTP_PORT=18888 kolibri-0.12.2.pex --foreground start`
* Import PHET English Channel

```
wget http://localhost:18888/kolibri/content/storage/5/4/541e70e8ed4325d5bed65595632ec22f.png -O /dev/null
```

Output:

```
--2019-04-23 12:59:01--  http://localhost:18888/kolibri/content/storage/5/4/541e70e8ed4325d5bed65595632ec22f.png
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:18888... connected.
HTTP request sent, awaiting response... 404 Not Found
2019-04-23 12:59:02 ERROR 404: Not Found.
```

### Expected behavior
<!--
Description of what behavior was expected but did not occur
-->

* Start Kolibri with: `KOLIBRI_URL_PATH_PREFIX=/ KOLIBRI_HTTP_PORT=18888 kolibri-0.12.2.pex --foreground start`
* Import PHET English Channel

```
wget http://localhost:18888/content/storage/5/4/541e70e8ed4325d5bed65595632ec22f.png -O /dev/null
```

Output
```
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:18888... connected.
HTTP request sent, awaiting response... 200 OK
```

### User-facing consequences
<!--
Implications and real-world consequences for learners, coaches, admins, and other users of the application
-->

When the KOLIBRI_URL_PATH_PREFIX is set to a path other than /, resources (images, pdf, videos, etc) will not be able to load from storage

### Errors and logs
<!--
Relevant logs from:
 * the command line
 * ~/.kolibri/kolibri.log
 * the browser console

Please wrap errors in triple backticks for clean formatting like this:
```
01:10 info: something happened
01:12 error: something bad happened
```
-->

See above

### Steps to reproduce
<!--
Precise steps that someone else can follow in order to see this behavior
-->

See above

### Context
<!--
Tell us about your environment, including:
 * Kolibri version
 * Operating system
 * Browser
-->

* kolibri-0.12.2.pex
* Ubuntu 18.04
* Any



Discussion:

Resolving patch:
diff --git a/kolibri/core/content/utils/paths.py b/kolibri/core/content/utils/paths.py
--- a/kolibri/core/content/utils/paths.py
+++ b/kolibri/core/content/utils/paths.py
@@ -140,6 +140,9 @@ def get_content_storage_file_url(filename, baseurl=None):
             kwargs={"zipped_filename": filename, "embedded_filepath": ""},
         )
     else:
-        return "{}{}/{}/{}".format(
-            get_content_storage_url(baseurl), filename[0], filename[1], filename
+        return "/{}{}/{}/{}".format(
+            get_content_storage_url(baseurl).lstrip("/"),
+            filename[0],
+            filename[1],
+            filename,
         )
diff --git a/kolibri/utils/server.py b/kolibri/utils/server.py
--- a/kolibri/utils/server.py
+++ b/kolibri/utils/server.py
@@ -258,9 +258,12 @@ def run_server(port):
     content_files_handler = cherrypy.tools.staticdir.handler(
         section="/", dir=paths.get_content_dir_path()
     )
+
+    url_path_prefix = conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]
+
     cherrypy.tree.mount(
         content_files_handler,
-        paths.get_content_url(conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]),
+        "/{}".format(paths.get_content_url(url_path_prefix).lstrip("/")),
         config={"/": {"tools.caching.on": False}},
     )
 


Test patch: