diff --git a/config.yml b/config.yml
index f32293a..5984055 100644
--- a/config.yml
+++ b/config.yml
@@ -8,8 +8,7 @@ log-level: warn
# Set the log output to one or more of the following: `stdout`, `file`. Default: stdout,file
log-output: stdout,file
-# Public URL for the Git HTTP/SSH connection.
-# If not set, uses the URL from the request
+# Public URL to access to Opengist
external-url:
# Directory where Opengist will store its data. Default: ~/.opengist/
diff --git a/docs/administration/nginx-reverse-proxy.md b/docs/administration/nginx-reverse-proxy.md
index 9accdb6..fdbdc80 100644
--- a/docs/administration/nginx-reverse-proxy.md
+++ b/docs/administration/nginx-reverse-proxy.md
@@ -1,6 +1,10 @@
# Use Nginx as a reverse proxy
-Configure Nginx to proxy requests to Opengist. Here is an example configuration file :
+Configure Nginx to proxy requests to Opengist. Here are example configuration file to use Opengist on a subdomain or on a subpath.
+
+Make sure you set the base url for Opengist via the [configuration](/docs/configuration/cheat-sheet.md).
+
+### Subdomain
```
server {
listen 80;
@@ -16,7 +20,27 @@ server {
}
```
-Then run :
-```shell
-service nginx restart
+### Subpath
+```
+server {
+ listen 80;
+ server_name example.com;
+
+ location /opengist/ {
+ rewrite ^/opengist(/.*)$ $1 break;
+ proxy_pass http://127.0.0.1:6157;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Prefix /opengist;
+ }
+}
+```
+
+---
+
+To apply changes:
+```shell
+sudo systemctl restart nginx
```
diff --git a/docs/configuration/cheat-sheet.md b/docs/configuration/cheat-sheet.md
index 67320a4..7368156 100644
--- a/docs/configuration/cheat-sheet.md
+++ b/docs/configuration/cheat-sheet.md
@@ -4,7 +4,7 @@
|-----------------------|--------------------------|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| log-level | OG_LOG_LEVEL | `warn` | Set the log level to one of the following: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic`. |
| log-output | OG_LOG_OUTPUT | `stdout,file` | Set the log output to one or more of the following: `stdout`, `file`. |
-| external-url | OG_EXTERNAL_URL | none | Public URL for the Git HTTP/SSH connection. If not set, uses the URL from the request. |
+| external-url | OG_EXTERNAL_URL | none | Public URL to access to Opengist. |
| opengist-home | OG_OPENGIST_HOME | home directory | Path to the directory where Opengist stores its data. |
| db-filename | OG_DB_FILENAME | `opengist.db` | Name of the SQLite database file. |
| git.default-branch | OG_GIT_DEFAULT_BRANCH | none | Default branch name used by Opengist when initializing Git repositories. If not set, uses the Git default branch name. More info [here](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup#_new_default_branch) |
diff --git a/internal/web/gist.go b/internal/web/gist.go
index ec8da50..beb51d0 100644
--- a/internal/web/gist.go
+++ b/internal/web/gist.go
@@ -323,7 +323,12 @@ func gistJson(ctx echo.Context) error {
jsUrl, err := url.JoinPath(getData(ctx, "baseHttpUrl").(string), gist.User.Username, gist.Identifier()+".js")
if err != nil {
- return errorRes(500, "Error joining url", err)
+ return errorRes(500, "Error joining js url", err)
+ }
+
+ cssUrl, err := url.JoinPath(getData(ctx, "baseHttpUrl").(string), manifestEntries["embed.css"].File)
+ if err != nil {
+ return errorRes(500, "Error joining css url", err)
}
return ctx.JSON(200, map[string]interface{}{
@@ -337,7 +342,7 @@ func gistJson(ctx echo.Context) error {
"files": renderedFiles,
"embed": map[string]string{
"html": htmlbuf.String(),
- "css": getData(ctx, "baseHttpUrl").(string) + asset("embed.css"),
+ "css": cssUrl,
"js": jsUrl,
"js_dark": jsUrl + "?dark",
},
@@ -365,10 +370,15 @@ func gistJs(ctx echo.Context) error {
}
_ = w.Flush()
+ cssUrl, err := url.JoinPath(getData(ctx, "baseHttpUrl").(string), manifestEntries["embed.css"].File)
+ if err != nil {
+ return errorRes(500, "Error joining css url", err)
+ }
+
js := `document.write('')
document.write('%s')
`
- js = fmt.Sprintf(js, getData(ctx, "baseHttpUrl").(string)+asset("embed.css"),
+ js = fmt.Sprintf(js, cssUrl,
strings.Replace(htmlbuf.String(), "\n", `\n`, -1))
ctx.Response().Header().Set("Content-Type", "application/javascript")
return plainText(ctx, 200, js)
diff --git a/public/admin.ts b/public/admin.ts
index a044a8d..56fa0ea 100644
--- a/public/admin.ts
+++ b/public/admin.ts
@@ -8,13 +8,14 @@ document.addEventListener('DOMContentLoaded', () => {
});
const setSetting = (key: string, value: string) => {
+ const baseUrl = window.opengist_base_url || '';
const data = new URLSearchParams();
data.append('key', key);
data.append('value', value);
if (document.getElementsByName('_csrf').length !== 0) {
data.append('_csrf', ((document.getElementsByName('_csrf')[0] as HTMLInputElement).value));
}
- return fetch('/admin-panel/set-config', {
+ return fetch(`${baseUrl}/admin-panel/set-config`, {
method: 'PUT',
credentials: 'same-origin',
body: data,
diff --git a/templates/base/base_header.html b/templates/base/base_header.html
index 4a571c6..565f62a 100644
--- a/templates/base/base_header.html
+++ b/templates/base/base_header.html
@@ -7,7 +7,10 @@
{{ end }}
+
+